Commit 9383ab92 authored by Romain Bioteau's avatar Romain Bioteau Committed by Adrien
Browse files

transactional_text_widget

parent 8516f8b1
......@@ -22,6 +22,7 @@ import org.bonitasoft.studio.ui.wizard.WizardBuilder;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.jface.wizard.IWizardContainer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
public class ImportBosHandler {
......@@ -40,6 +41,7 @@ public class ImportBosHandler {
Messages.bind(Messages.importFileDescription, new Object[] { bonitaStudioModuleName }))
.withControl(bosArchiveControlSupplier))
.onFinish(container -> onFinishOperation(bosArchiveControlSupplier, repositoryAccessor, container))
.withSize(SWT.DEFAULT, 700)
.open(activeShell, Messages.importButtonLabel);
try {
......
......@@ -54,6 +54,6 @@ public class ImportArchiveModel {
* set all the conflict status to none
*/
public void resetStatus() {
stores.stream().forEach(store -> store.resetStatus());
stores.stream().forEach(ImportStoreModel::resetStatus);
}
}
......@@ -66,6 +66,8 @@ import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.forms.events.ExpansionEvent;
import org.eclipse.ui.forms.events.IExpansionListener;
import org.eclipse.ui.forms.widgets.Section;
public class ImportBosArchiveControlSupplier implements ControlSupplier {
......@@ -128,7 +130,7 @@ public class ImportBosArchiveControlSupplier implements ControlSupplier {
final Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(GridLayoutFactory.fillDefaults().spacing(LayoutConstants.getSpacing().x, 1).create());
composite.setLayoutData(
GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 400).create());
GridDataFactory.fillDefaults().grab(true, true).create());
createTreeHeader(composite, dbc);
treeSection.setClient(createTree(treeSection));
}
......@@ -138,6 +140,7 @@ public class ImportBosArchiveControlSupplier implements ControlSupplier {
treeSection.setLayout(GridLayoutFactory.fillDefaults().create());
treeSection.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
treeSection.setText(Messages.importDetails);
treeSection.addExpansionListener(new UpdateLayoutListener(parent));
treeSection.setExpanded(false);
descriptionLabel = new Label(treeSection, SWT.WRAP);
archiveStatusObservable = PojoObservables.observeValue(this, "archiveStatus");
......@@ -167,7 +170,6 @@ public class ImportBosArchiveControlSupplier implements ControlSupplier {
private Composite createTree(Composite parent) {
final Composite fileTreeGroup = new Composite(parent, SWT.NONE);
fileTreeGroup.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 5).create());
fileTreeGroup.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
viewer = new TreeViewer(fileTreeGroup,
......@@ -256,6 +258,7 @@ public class ImportBosArchiveControlSupplier implements ControlSupplier {
private void updateFilePath(String filePath) {
textWidget.setText(filePath);
textWidget.getParent().getParent().layout();
if (new File(filePath).exists()) {
savePath(filePath);
} else {
......@@ -307,7 +310,6 @@ public class ImportBosArchiveControlSupplier implements ControlSupplier {
}
protected void openTree() {
treeSection.setExpanded(true);
archiveStatusObservable.setValue(archiveModel.getStatus());
if (archiveModel.isConflicting()) {
final TreeItem[] items = viewer.getTree().getItems();
......@@ -328,11 +330,12 @@ public class ImportBosArchiveControlSupplier implements ControlSupplier {
keepAllButton.disable();
overwriteButton.disable();
} else {
descriptionLabel.setText(Messages.noConflictMessage);
treeSection.getDescriptionControl().setForeground(successColor);
keepAllButton.disable();
overwriteButton.disable();
}
descriptionLabel.getParent().layout();
treeSection.setExpanded(true);
}
protected String getAlreadyPresentMessage() {
......@@ -396,4 +399,32 @@ public class ImportBosArchiveControlSupplier implements ControlSupplier {
public void setArchiveStatus(ConflictStatus archiveStatus) {
this.archiveStatus = archiveStatus;
}
protected class UpdateLayoutListener implements IExpansionListener {
private final Composite toLayout;
public UpdateLayoutListener(Composite toLayout) {
this.toLayout = toLayout;
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.forms.events.IExpansionListener#expansionStateChanging(org.eclipse.ui.forms.events.ExpansionEvent)
*/
@Override
public void expansionStateChanging(ExpansionEvent e) {
//NOTHING TO DO
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.forms.events.IExpansionListener#expansionStateChanged(org.eclipse.ui.forms.events.ExpansionEvent)
*/
@Override
public void expansionStateChanged(ExpansionEvent e) {
toLayout.layout();
}
}
}
errorOccuredDuringFinish=An error occurred during the finish operation.\nYou may check studio log file for more insight.
errorTitle=Error
\ No newline at end of file
errorTitle=Error
edit=Edit
applyEdit=Apply
revertEdit=Revert
\ No newline at end of file
......@@ -14,6 +14,7 @@
*/
package org.bonitasoft.studio.ui.wizard;
import static org.bonitasoft.studio.ui.databinding.UpdateStrategyFactory.convertUpdateValueStrategy;
import static org.bonitasoft.studio.ui.databinding.UpdateStrategyFactory.updateValueStrategy;
import static org.bonitasoft.studio.ui.wizard.WizardBuilder.newWizard;
import static org.bonitasoft.studio.ui.wizard.WizardPageBuilder.newPage;
......@@ -102,12 +103,14 @@ public class WizardBuilderTest {
.withLabel("Name")
.withLayoutData(GridDataFactory.fillDefaults().grab(true, false).create())
.labelAbove()
.withButton("button")
.withMessage("Example: Jean, Marie ...")
//.withButton("button")
.transactionalEdit((a, b) -> System.out
.println(String.format("Old value: %s , New value: %s", a, b)))
// .withMessage("Example: Jean, Marie ...")
.bindTo(PojoObservables.observeValue(person, "name"))
.inContext(ctx)
.withTargetToModelStrategy(
updateValueStrategy().withValidator(new EmptyInputValidator.Builder()
convertUpdateValueStrategy().withValidator(new EmptyInputValidator.Builder()
.withMessage("Name is mandatory").create()))
.createIn(container);
......
......@@ -3,7 +3,7 @@
* BonitaSoft is a trademark of BonitaSoft SA.
* This software file is BONITASOFT CONFIDENTIAL. Not For Distribution.
* For commercial licensing information, contact:
* BonitaSoft, 32 rue Gustave Eiffel 38000 Grenoble
* BonitaSoft, 32 rue Gustave Eiffel 38000 Grenoble
* or BonitaSoft US, 51 Federal Street, Suite 305, San Francisco, CA 94107
*******************************************************************************/
package org.bonitasoft.studio.ui;
......@@ -16,5 +16,6 @@ public interface ColorConstants {
static final RGB WARNING_RGB = new RGB(155, 170, 20);
static final RGB SUCCESS_RGB = new RGB(60, 130, 40);
static final RGB BLUE_RGB = new RGB(0, 0, 200);
static final RGB EDITING_RGB = new RGB(62, 190, 222);
}
......@@ -24,5 +24,8 @@ public class Messages extends NLS {
public static String errorOccuredDuringFinish;
public static String errorTitle;
public static String revertEdit;
public static String applyEdit;
public static String edit;
}
......@@ -40,6 +40,7 @@ public class ButtonWidget extends ControlWidget {
@Override
public ButtonWidget createIn(Composite container) {
final ButtonWidget control = new ButtonWidget(container);
control.init();
control.setLayoutData(layoutData != null ? layoutData : gridData);
if (this.label != null) {
control.setText(label);
......@@ -57,6 +58,11 @@ public class ButtonWidget extends ControlWidget {
super(parent);
}
@Override
protected int numColumn() {
return 1;
}
/**
* enable the possibility to click on the button
*/
......
......@@ -38,8 +38,10 @@ public class ComboWidget extends EditableControlWidget {
@Override
public ComboWidget createIn(Composite container) {
final ComboWidget control = new ComboWidget(container, labelAbove, horizontalLabelAlignment,
verticalLabelAlignment, labelWidth, readOnly, label, message);
final ComboWidget control = new ComboWidget(container, id, labelAbove, horizontalLabelAlignment,
verticalLabelAlignment, labelWidth, readOnly, label,
message);
control.init();
control.setLayoutData(layoutData != null ? layoutData : gridData);
control.setItems(items);
if (ctx != null && modelObservable != null) {
......@@ -52,9 +54,12 @@ public class ComboWidget extends EditableControlWidget {
private CCombo combo;
protected ComboWidget(Composite container, boolean topLabel, int horizontalLabelAlignment, int verticalLabelAlignment,
int labelWidth, boolean readOnly, String label, String message) {
super(container, topLabel, horizontalLabelAlignment, verticalLabelAlignment, labelWidth, readOnly, label, message);
protected ComboWidget(Composite container, String id, boolean topLabel, int horizontalLabelAlignment,
int verticalLabelAlignment,
int labelWidth, boolean readOnly,
String label, String message) {
super(container, id, topLabel, horizontalLabelAlignment, verticalLabelAlignment, labelWidth, readOnly, label,
message);
}
public ISWTObservableValue observeComboText() {
......@@ -85,6 +90,7 @@ public class ComboWidget extends EditableControlWidget {
}
combo = new CCombo(container, SWT.SINGLE | textStyle);
combo.setData(SWTBOT_WIDGET_ID_KEY, id);
combo.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
combo.addListener(SWT.FocusIn, event -> redraw(container));
combo.addListener(SWT.FocusOut, event -> redraw(container));
......
......@@ -16,8 +16,6 @@ package org.bonitasoft.studio.ui.widget;
import java.util.Optional;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.layout.LayoutConstants;
......@@ -29,56 +27,75 @@ import org.eclipse.ui.forms.widgets.FormToolkit;
public abstract class ControlWidget extends Composite {
protected static final String SWTBOT_WIDGET_ID_KEY = "org.eclipse.swtbot.widget.key";
protected Optional<Label> label = Optional.empty();
protected Optional<Label> filler = Optional.empty();
protected IStatus status = ValidationStatus.ok();
// protected IStatus status = ValidationStatus.ok();
protected Optional<String> message = Optional.empty();
protected boolean readOnly = false;
protected boolean labelAbove = false;
protected Control control;
protected Optional<String> buttonLabel = Optional.empty();
private final int horizontalLabelAlignment;
private final int verticalLabelAlignment;
private final int labelHint;
private final String labelValue;
protected ControlWidget(Composite parent, boolean labelAbove, int horizontalLabelAlignment, int verticalLabelAlignment,
int labelHint, String labelValue, String message) {
super(parent, SWT.NONE);
init(labelAbove, horizontalLabelAlignment, verticalLabelAlignment, labelHint, labelValue, message);
protected String id;
protected ControlWidget(Composite parent,
String id,
boolean labelAbove,
int horizontalLabelAlignment,
int verticalLabelAlignment,
int labelHint,
String labelValue,
String message) {
this(parent, id, labelAbove, horizontalLabelAlignment, verticalLabelAlignment, labelHint, false, labelValue, message,
Optional.empty());
}
protected ControlWidget(Composite parent, boolean labelAbove, int horizontalLabelAlignment, int verticalLabelAlignment,
int labelHint, boolean readOnly, String labelValue, String message, Optional<String> buttonLabel) {
protected ControlWidget(Composite parent,
String id,
boolean labelAbove,
int horizontalLabelAlignment,
int verticalLabelAlignment,
int labelHint,
boolean readOnly,
String labelValue,
String message,
Optional<String> buttonLabel) {
super(parent, SWT.NONE);
this.id = id;
this.buttonLabel = buttonLabel;
this.readOnly = readOnly;
init(labelAbove, horizontalLabelAlignment, verticalLabelAlignment, labelHint, labelValue, message);
this.labelAbove = labelAbove;
this.horizontalLabelAlignment = horizontalLabelAlignment;
this.verticalLabelAlignment = verticalLabelAlignment;
this.labelHint = labelHint;
this.labelValue = labelValue;
this.message = Optional.ofNullable(message);
}
protected ControlWidget(Composite parent) {
super(parent, SWT.NONE);
setLayout(GridLayoutFactory.fillDefaults()
.numColumns(1)
.spacing(LayoutConstants.getSpacing().x, 1)
.create());
control = createControl();
this(parent, null, false, 0, 0, 0, false, null, null, Optional.empty());
}
private void init(boolean labelAbove, int horizontalLabelAlignment, int verticalLabelAlignment, int labelHint,
String labelValue, String message) {
this.message = Optional.ofNullable(message);
this.labelAbove = labelAbove;
protected void init() {
setLayout(GridLayoutFactory.fillDefaults()
.numColumns(buttonLabel.isPresent() ? 3 : 2)
.spacing(LayoutConstants.getSpacing().x, 1)
.numColumns(numColumn())
.spacing(horizontalSpacing(), 1)
.create());
final Optional<String> labelText = Optional.ofNullable(labelValue);
labelText.ifPresent(text -> {
Label lab = new Label(this, SWT.NONE);
final Label lab = new Label(this, SWT.NONE);
lab.setLayoutData(GridDataFactory.swtDefaults()
.align(labelAbove ? SWT.LEFT : horizontalLabelAlignment, verticalLabelAlignment)
.span(labelAbove ? 2 : 1, 1).create());
lab.setText(text);
label = Optional.ofNullable(lab);
label = Optional.of(lab);
});
control = createControl();
......@@ -90,8 +107,12 @@ public abstract class ControlWidget extends Composite {
public abstract Control adapt(FormToolkit toolkit);
public IStatus getStatus() {
return status;
protected int numColumn() {
return buttonLabel.isPresent() ? 3 : 2;
}
protected int horizontalSpacing() {
return LayoutConstants.getSpacing().x;
}
protected abstract Control createControl();
......
......@@ -40,6 +40,7 @@ public abstract class ControlWidgetBuilder<T, W extends ControlWidget> {
protected Object layoutData;
protected IObservableValue modelObservable;
protected DataBindingContext ctx;
protected String id;
/**
* Adds a text label next to the control.
......@@ -51,6 +52,11 @@ public abstract class ControlWidgetBuilder<T, W extends ControlWidget> {
return (T) this;
}
public T withId(String id) {
this.id = id;
return (T) this;
}
/**
* Set the position of the text label above the control.
*/
......
/*******************************************************************************
* Copyright (C) 2016 BonitaSoft S.A.
* BonitaSoft is a trademark of BonitaSoft SA.
* This software file is BONITASOFT CONFIDENTIAL. Not For Distribution.
* For commercial licensing information, contact:
* BonitaSoft, 32 rue Gustave Eiffel � 38000 Grenoble
* or BonitaSoft US, 51 Federal Street, Suite 305, San Francisco, CA 94107
*******************************************************************************/
/**
* Copyright (C) 2017 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.ui.widget;
import java.util.Optional;
......@@ -17,14 +23,13 @@ import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.resource.LocalResourceManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
......@@ -37,66 +42,62 @@ public abstract class EditableControlWidget extends ControlWidget {
public static final int MESSAGE_GRAY_STYLE = 1;
public static final int MESSAGE_DEFAULT_STYLE = 0;
private LocalResourceManager resourceManager;
private Color errorColor;
private Color warningColor;
protected final LocalResourceManager resourceManager;
private final Color errorColor;
private final Color warningColor;
private Binding valueBinding;
private WidgetMessageDecorator messageDecorator;
private int messageStyle = MESSAGE_DEFAULT_STYLE;
protected IStatus status = Status.OK_STATUS;
protected EditableControlWidget(Composite parent, boolean labelAbove, int horizontalLabelAlignment,
int verticalLabelAlignment, int labelHint, boolean readOnly, String labelValue, String message) {
this(parent, labelAbove, horizontalLabelAlignment, verticalLabelAlignment, labelHint, readOnly, labelValue, message,
Optional.empty());
protected EditableControlWidget(Composite parent, String id, boolean labelAbove, int horizontalLabelAlignment,
int verticalLabelAlignment, int labelHint,
boolean readOnly, String labelValue, String message) {
this(parent, id, labelAbove, horizontalLabelAlignment, verticalLabelAlignment, labelHint, readOnly, labelValue,
message, Optional.empty());
}
protected EditableControlWidget(Composite parent, boolean labelAbove, int horizontalLabelAlignment,
protected EditableControlWidget(Composite parent, String id, boolean labelAbove, int horizontalLabelAlignment,
int verticalLabelAlignment, int labelHint, boolean readOnly, String labelValue, String message,
Optional<String> buttonLabel) {
super(parent, labelAbove, horizontalLabelAlignment, verticalLabelAlignment, labelHint, readOnly, labelValue, message,
buttonLabel);
initEditable(parent, labelAbove, readOnly, message);
}
protected void initEditable(Composite parent, boolean labelAbove, boolean readOnly, String message) {
this.readOnly = readOnly;
super(parent, id, labelAbove, horizontalLabelAlignment, verticalLabelAlignment, labelHint, readOnly, labelValue,
message, buttonLabel);
this.resourceManager = new LocalResourceManager(JFaceResources.getResources(), parent);
errorColor = resourceManager.createColor(ColorConstants.ERROR_RGB);
warningColor = resourceManager.createColor(ColorConstants.WARNING_RGB);
messageDecorator = new WidgetMessageDecorator(this);
}
/*
* (non-Javadoc)
* @see org.bonitasoft.studio.ui.widget.ControlWidget#init()
*/
@Override
protected void init() {
super.init();
messageDecorator = new WidgetMessageDecorator(this, message);
messageDecorator
.setLayoutData(GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.TOP)
.span(messageLabelHorizontalSpan(labelAbove), 1).indent(0, -2).create());
setMessageColor();
messageDecorator.setMessage(message);
messageDecorator.updateExpandState();
.setLayoutData(GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.FILL).grab(true, false)
.span(messageLabelHorizontalSpan(labelAbove), 1).indent(0, messageDecoratorVerticalIndent())
.create());
messageDecorator.setStatus(status);
}
private int messageLabelHorizontalSpan(boolean labelAbove) {
protected int messageDecoratorVerticalIndent() {
return -2;
}
protected int messageLabelHorizontalSpan(boolean labelAbove) {
return buttonLabel.isPresent() ? horizontalSpanWithButton(labelAbove) : 1;
}
private int horizontalSpanWithButton(boolean labelAbove) {
protected int horizontalSpanWithButton(boolean labelAbove) {
return labelAbove ? 3 : 2;
}
@Override
protected abstract Control createControl();
protected Color getStatusColor(IStatus status) {
return status.getSeverity() == IStatus.WARNING ? warningColor
: status.getSeverity() == IStatus.ERROR ? errorColor
: Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND);
}
protected Color getBorderColor(Control focused, Control container) {
if (status.isOK() || status.getSeverity() == IStatus.INFO) {
if (focused != null && focused.getParent() != null && focused.getParent().equals(container)) {
return container.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BORDER);
}
return container.getDisplay().getSystemColor(SWT.COLOR_GRAY);
}
return getStatusColor(status);
protected Color selectedBorderColor(Control container) {
return container.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BORDER);
}
protected void drawBorder(final Composite container, Event e) {
......@@ -112,9 +113,23 @@ public abstract class EditableControlWidget extends ControlWidget {
}
}
private Image getStatusImage(IStatus status) {
return status.getSeverity() == IStatus.WARNING ? JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING)
: status.getSeverity() == IStatus.ERROR ? JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR) : null;
protected Color getStatusColor(IStatus status) {
if (status == null) {
return Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND);
}
return status.getSeverity() == IStatus.WARNING ? warningColor
: status.getSeverity() == IStatus.ERROR ? errorColor
: Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND);
}
protected Color getBorderColor(Control focused, Control container) {
if (status.isOK() || status.getSeverity() == IStatus.INFO) {
if (focused != null && focused.getParent() != null && focused.getParent().equals(container)) {
return selectedBorderColor(container);
}
return container.getDisplay().getSystemColor(SWT.COLOR_GRAY);
}
return getStatusColor(status);
}