Commit dddb0fd6 authored by Romain Bioteau's avatar Romain Bioteau Committed by GitHub
Browse files

fix(expressionDialog) fix name reset for Query Expressions (#393)

Closes BS-16454
parent 7de860de
/**
* Copyright (C) 2010-2012 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/>.
*/
......@@ -80,8 +77,10 @@ public class ReferencedExpressionEditingSupport extends EditingSupport {
@Override
protected CellEditor getCellEditor(final Object element) {
final ExpressionViewerCellEditor editor = new ExpressionViewerCellEditor(
getViewer(), (Composite) getViewer().getControl(),
editingDomain, 0, null);
getViewer(),
(Composite) getViewer().getControl(),
editingDomain,
null);
if (expressionNatureProvider != null) {
editor.setExpressionNatureProvider(expressionNatureProvider);
}
......
/**
* Copyright (C) 2010-2012 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
* 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/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.expression.editor.viewer;
......@@ -46,148 +43,149 @@ import org.eclipse.swt.widgets.Event;
*/
public class ExpressionCollectionEditingSupport extends EditingSupport {
protected Object context;
protected final int colIndex;
protected final List<ViewerFilter> filters;
protected EditingDomain editingDomain;
private IExpressionNatureProvider expressionNatureProvider;
private final SelectionListener removeRowListener;
private IExpressionProposalLabelProvider expressionProposalLabelProvider;
/**
* @param viewer
* @param textOrDataFactory
* @param dontUseFormField
*/
public ExpressionCollectionEditingSupport(final ColumnViewer viewer, final int colIndex, final SelectionListener removeRowListener) {
this(viewer, colIndex, null, removeRowListener);
}
public ExpressionCollectionEditingSupport(final ColumnViewer viewer,
final int colIndex, final EditingDomain editingDomain, final SelectionListener removeRowListener) {
super(viewer);
this.colIndex = colIndex;
filters = new ArrayList<ViewerFilter>();
this.editingDomain = editingDomain;
this.removeRowListener = removeRowListener;
}
@Override
protected void initializeCellEditorValue(final CellEditor cellEditor,
final ViewerCell cell) {
super.initializeCellEditorValue(cellEditor, cell);
cell.setImage(null);
cell.setText("");
}
@Override
protected void setValue(final Object element, final Object value) {
getViewer().refresh();
getViewer().getControl().notifyListeners(SWT.Selection, new Event());
}
@Override
protected Object getValue(final Object element) {
return element;
}
@Override
protected CellEditor getCellEditor(final Object element) {
final ExpressionViewerCellEditor editor = new ExpressionViewerCellEditor(
getViewer(), (Composite) getViewer().getControl(),
editingDomain,colIndex,removeRowListener);
if (expressionNatureProvider != null) {
editor.setExpressionNatureProvider(expressionNatureProvider);
}
if(expressionProposalLabelProvider != null){
editor.setExpressionProposalLableProvider(expressionProposalLabelProvider);
}
for (final ViewerFilter filter : filters) {
editor.addFilter(filter);
}
if (context != null) {
editor.setInput(context);
}
if (element instanceof Expression) {
editor.setSelection(new StructuredSelection(element));
}
if (element instanceof ListExpression) {
final List<Expression> list = ((ListExpression) element).getExpressions();
for (int i = 0; i <= colIndex; i++) {
if (i < list.size()) {
if (list.get(i) == null) {
if (editingDomain != null) {
editingDomain
.getCommandStack()
.execute(
AddCommand
.create(editingDomain,
element,
ExpressionPackage.Literals.LIST_EXPRESSION__EXPRESSIONS,
ExpressionFactory.eINSTANCE
.createExpression(),
i));
} else {
list.add(i, ExpressionFactory.eINSTANCE
.createExpression());
}
}
} else {
if (editingDomain != null) {
editingDomain
.getCommandStack()
.execute(
AddCommand
.create(editingDomain,
element,
ExpressionPackage.Literals.LIST_EXPRESSION__EXPRESSIONS,
ExpressionFactory.eINSTANCE
.createExpression(),
i));
} else {
list.add(i,
ExpressionFactory.eINSTANCE.createExpression());
}
}
}
editor.setSelection(new StructuredSelection(
((ListExpression) element).getExpressions().get(colIndex)));
}
return editor;
}
@Override
protected boolean canEdit(final Object element) {
return true;
}
public void setInput(final Object input) {
context = input;
}
public void addFilter(final ViewerFilter filter) {
filters.add(filter);
}
public void setEditingDomain(final EditingDomain editingDomain) {
this.editingDomain = editingDomain;
}
@Override
protected void saveCellEditorValue(final CellEditor cellEditor, final ViewerCell cell) {
super.saveCellEditorValue(cellEditor, cell);
ExpressionCollectionEditingSupport.this.getViewer().refresh();
}
public void setExpressionNatureProvider(
final IExpressionNatureProvider expressionNatureProvider) {
this.expressionNatureProvider = expressionNatureProvider;
}
public void setExpressionProposalLableProvider(final IExpressionProposalLabelProvider expressionProposalLabelProvider) {
this.expressionProposalLabelProvider = expressionProposalLabelProvider;
}
protected Object context;
protected final int colIndex;
protected final List<ViewerFilter> filters;
protected EditingDomain editingDomain;
private IExpressionNatureProvider expressionNatureProvider;
private final SelectionListener removeRowListener;
private IExpressionProposalLabelProvider expressionProposalLabelProvider;
/**
* @param viewer
* @param textOrDataFactory
* @param dontUseFormField
*/
public ExpressionCollectionEditingSupport(final ColumnViewer viewer, final int colIndex,
final SelectionListener removeRowListener) {
this(viewer, colIndex, null, removeRowListener);
}
public ExpressionCollectionEditingSupport(final ColumnViewer viewer,
final int colIndex, final EditingDomain editingDomain, final SelectionListener removeRowListener) {
super(viewer);
this.colIndex = colIndex;
filters = new ArrayList<ViewerFilter>();
this.editingDomain = editingDomain;
this.removeRowListener = removeRowListener;
}
@Override
protected void initializeCellEditorValue(final CellEditor cellEditor,
final ViewerCell cell) {
super.initializeCellEditorValue(cellEditor, cell);
cell.setImage(null);
cell.setText("");
}
@Override
protected void setValue(final Object element, final Object value) {
getViewer().refresh();
getViewer().getControl().notifyListeners(SWT.Selection, new Event());
}
@Override
protected Object getValue(final Object element) {
return element;
}
@Override
protected CellEditor getCellEditor(final Object element) {
final ExpressionViewerCellEditor editor = new ExpressionViewerCellEditor(
getViewer(), (Composite) getViewer().getControl(),
editingDomain, removeRowListener);
if (expressionNatureProvider != null) {
editor.setExpressionNatureProvider(expressionNatureProvider);
}
if (expressionProposalLabelProvider != null) {
editor.setExpressionProposalLableProvider(expressionProposalLabelProvider);
}
for (final ViewerFilter filter : filters) {
editor.addFilter(filter);
}
if (context != null) {
editor.setInput(context);
}
if (element instanceof Expression) {
editor.setSelection(new StructuredSelection(element));
}
if (element instanceof ListExpression) {
final List<Expression> list = ((ListExpression) element).getExpressions();
for (int i = 0; i <= colIndex; i++) {
if (i < list.size()) {
if (list.get(i) == null) {
if (editingDomain != null) {
editingDomain
.getCommandStack()
.execute(
AddCommand
.create(editingDomain,
element,
ExpressionPackage.Literals.LIST_EXPRESSION__EXPRESSIONS,
ExpressionFactory.eINSTANCE
.createExpression(),
i));
} else {
list.add(i, ExpressionFactory.eINSTANCE
.createExpression());
}
}
} else {
if (editingDomain != null) {
editingDomain
.getCommandStack()
.execute(
AddCommand
.create(editingDomain,
element,
ExpressionPackage.Literals.LIST_EXPRESSION__EXPRESSIONS,
ExpressionFactory.eINSTANCE
.createExpression(),
i));
} else {
list.add(i,
ExpressionFactory.eINSTANCE.createExpression());
}
}
}
editor.setSelection(new StructuredSelection(
((ListExpression) element).getExpressions().get(colIndex)));
}
return editor;
}
@Override
protected boolean canEdit(final Object element) {
return true;
}
public void setInput(final Object input) {
context = input;
}
public void addFilter(final ViewerFilter filter) {
filters.add(filter);
}
public void setEditingDomain(final EditingDomain editingDomain) {
this.editingDomain = editingDomain;
}
@Override
protected void saveCellEditorValue(final CellEditor cellEditor, final ViewerCell cell) {
super.saveCellEditorValue(cellEditor, cell);
ExpressionCollectionEditingSupport.this.getViewer().refresh();
}
public void setExpressionNatureProvider(
final IExpressionNatureProvider expressionNatureProvider) {
this.expressionNatureProvider = expressionNatureProvider;
}
public void setExpressionProposalLableProvider(final IExpressionProposalLabelProvider expressionProposalLabelProvider) {
this.expressionProposalLabelProvider = expressionProposalLabelProvider;
}
}
......@@ -67,7 +67,7 @@ public class ExpressionViewerCellEditor extends CellEditor {
private final Composite parent;
public ExpressionViewerCellEditor(final ColumnViewer columnViewer,
final Composite parent, final EditingDomain editingDomain, final int colIndex,
final Composite parent, final EditingDomain editingDomain,
final SelectionListener removeRowListener) {
super(parent);
this.editingDomain = editingDomain;
......
......@@ -5,14 +5,12 @@
* 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
* 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/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.expression.editor.viewer;
......@@ -26,26 +24,26 @@ import org.eclipse.swt.widgets.Shell;
/**
* @author Romain Bioteau
*
*/
public class GroovyOnlyEditExpressionDialog extends EditExpressionDialog {
protected GroovyOnlyEditExpressionDialog(final Shell parentShell, final boolean isPassword, final Expression inputExpression, final EObject context,
protected GroovyOnlyEditExpressionDialog(final Shell parentShell, final boolean isPassword,
final Expression inputExpression, final EObject context,
final EditingDomain domain, final ViewerFilter[] viewerTypeFilters, final ExpressionViewer expressionViewer) {
super(parentShell,isPassword,inputExpression,context,domain,viewerTypeFilters,expressionViewer);
this.inputExpression.setType(ExpressionConstants.SCRIPT_TYPE) ;
}
super(parentShell, isPassword, inputExpression, context, domain, viewerTypeFilters, expressionViewer);
this.inputExpression.setType(ExpressionConstants.SCRIPT_TYPE);
}
@Override
protected void createExpressionTypePanel(final Composite parentForm) {
@Override
protected void createExpressionTypePanel(final Composite parentForm) {
//DO NOT CREATE EXPRESSION TYPE PANEL
}
}
@Override
public void create() {
super.create();
showContent(ExpressionConstants.SCRIPT_TYPE);
getShell().layout(true,true);
}
@Override
public void create() {
super.create();
showContent(ExpressionConstants.SCRIPT_TYPE);
getShell().layout(true, true);
}
}
......@@ -5,12 +5,10 @@
* 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/>.
*/
......@@ -35,11 +33,11 @@ import org.eclipse.swt.widgets.Shell;
/**
* @author Romain Bioteau
*
*/
public class GroovyScriptFileDialog extends EditExpressionDialog {
public GroovyScriptFileDialog(Shell parentShell, Expression inputExpression, EObject context, EditingDomain domain, ViewerFilter[] viewerTypeFilters) {
public GroovyScriptFileDialog(Shell parentShell, Expression inputExpression, EObject context, EditingDomain domain,
ViewerFilter[] viewerTypeFilters) {
super(parentShell, false, inputExpression, context, domain, viewerTypeFilters, null);
if (isResizable()) {
setShellStyle(SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.MAX | SWT.RESIZE
......@@ -71,7 +69,6 @@ public class GroovyScriptFileDialog extends EditExpressionDialog {
}
dataBindingContext = new EMFDataBindingContext();
currentExpressionEditor.createExpressionEditor(contentComposite, dataBindingContext);
contentComposite.layout(true, true);
if (helpControl != null) {
helpControl.setVisible(currentExpressionEditor.provideDialogTray());
if (getTray() != null) {
......
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