Commit e097c94c authored by Romain Bioteau's avatar Romain Bioteau

add shortcut in contract property section

parent ee201cf9
/**
* Copyright (C) 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.common.properties;
import org.eclipse.gmf.runtime.diagram.ui.properties.sections.AbstractModelerPropertySection;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.swt.SWT;
......@@ -39,9 +37,8 @@ public abstract class AbstractBonitaDescriptionSection extends AbstractModelerPr
protected Form form;
private TabbedPropertySheetPage tabbedPropertySheetPage;
@Override
public void refresh(){
public void refresh() {
super.refresh();
if (form != null) {
form.setText(getSectionTitle());
......@@ -53,35 +50,42 @@ public abstract class AbstractBonitaDescriptionSection extends AbstractModelerPr
super.createControls(parent, aTabbedPropertySheetPage);
parent.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).create());
tabbedPropertySheetPage=aTabbedPropertySheetPage;
tabbedPropertySheetPage = aTabbedPropertySheetPage;
final TabbedPropertySheetWidgetFactory widgetFactory = tabbedPropertySheetPage.getWidgetFactory();
form = widgetFactory.createForm(parent);
form.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).create());
form.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
form.setText(getSectionTitle());
final Composite formBodyComposite = form.getBody();
formBodyComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).create());
formBodyComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
form.setToolBarVerticalAlignment(SWT.CENTER);
final TogglePropertyHelpContributionItem togglePropertyHelpContributionItem = new TogglePropertyHelpContributionItem(widgetFactory, form,
getSectionDescription());
updateToolbar(form.getToolBarManager());
form.getToolBarManager().add(togglePropertyHelpContributionItem);
form.getToolBarManager().update(true);
form.setText(getSectionTitle());
createContent(formBodyComposite);
form.getMenuManager().add(togglePropertyHelpContributionItem);
createContent(formBodyComposite);
form.update();
form.setFocus();
}
protected void updateToolbar(final IToolBarManager toolbarManager) {
//intended to be subclassed
}
protected abstract void createContent(final Composite parent);
@Override
public void dispose(){
public void dispose() {
super.dispose();
if (section!=null){
if (section != null) {
section.dispose();
}
}
......@@ -93,7 +97,6 @@ public abstract class AbstractBonitaDescriptionSection extends AbstractModelerPr
return null;
}
public TabbedPropertySheetPage getTabbedPropertySheetPage() {
return tabbedPropertySheetPage;
}
......@@ -108,5 +111,4 @@ public abstract class AbstractBonitaDescriptionSection extends AbstractModelerPr
public abstract String getSectionDescription();
}
......@@ -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/>.
*/
......@@ -34,10 +32,8 @@ import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormToolkit;
/**
* @author Romain Bioteau
*
*/
public class TogglePropertyHelpContributionItem implements IContributionItem {
......@@ -122,11 +118,15 @@ public class TogglePropertyHelpContributionItem implements IContributionItem {
decriptionLabel.dispose();
form.setHeadClient(null);
decriptionLabel = null;
menuItem.setText(Messages.showHelp);
if (menuItem != null) {
menuItem.setText(Messages.showHelp);
}
} else {
decriptionLabel = toolkit.createLabel(form.getHead(), helpContent, SWT.WRAP);
form.setHeadClient(decriptionLabel);
menuItem.setText(Messages.hideHelp);
if (menuItem != null) {
menuItem.setText(Messages.hideHelp);
}
}
form.getParent().getParent().layout(true, true);
}
......@@ -138,8 +138,6 @@ public class TogglePropertyHelpContributionItem implements IContributionItem {
toolItem.setImage(JFaceResources.getImage(Dialog.DLG_IMG_HELP));
toolItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
toggleHelp();
......@@ -150,9 +148,9 @@ public class TogglePropertyHelpContributionItem implements IContributionItem {
@Override
public void fill(final Menu parent, final int index) {
menuItem = new MenuItem(parent, SWT.PUSH);
if(decriptionLabel==null){
if (decriptionLabel == null) {
menuItem.setText(Messages.showHelp);
}else{
} else {
menuItem.setText(Messages.hideHelp);
}
......
......@@ -41,7 +41,10 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.9.0",
org.eclipse.gmf.runtime.diagram.ui,
org.eclipse.emf.edit.ui,
org.eclipse.jface.databinding;bundle-version="1.6.200",
org.eclipse.gmf.runtime.diagram.ui.properties;bundle-version="1.7.0"
org.eclipse.gmf.runtime.diagram.ui.properties;bundle-version="1.7.0",
org.eclipse.e4.core.di,
org.bonitasoft.studio.pagedesigner;bundle-version="7.0.0",
org.bonitasoft.studio.preferences;bundle-version="7.0.0"
Bundle-Activator: org.bonitasoft.studio.contract.ContractPlugin
Bundle-ActivationPolicy: lazy
Export-Package: org.bonitasoft.studio.contract.core,
......
......@@ -35,4 +35,5 @@ constraintEditorDescription=Type the constraint using MVEL scripting.\nUse Ctrl+
addContentToConstraint=Add content to constraint {0}
editContentToConstraint=Edit content to constraint {0}
emptyExpressionContent=Empty expression content
noContractInputReferencedInExpression=No contract input is referenced in the expression
\ No newline at end of file
noContractInputReferencedInExpression=No contract input is referenced in the expression
newFormTooltip=Create a new Form that will be mapped to this step
\ No newline at end of file
......@@ -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/>.
*/
......@@ -18,10 +16,8 @@ package org.bonitasoft.studio.contract.i18n;
import org.eclipse.osgi.util.NLS;
/**
* @author Romain Bioteau
*
*/
public class Messages extends NLS {
......@@ -67,5 +63,6 @@ public class Messages extends NLS {
public static String editContentToConstraint;
public static String emptyExpressionContent;
public static String noContractInputReferencedInExpression;
public static String newFormTooltip;
}
......@@ -5,19 +5,19 @@
* 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.contract.ui.property;
import javax.inject.Inject;
import org.bonitasoft.studio.common.jface.databinding.CustomEMFEditObservables;
import org.bonitasoft.studio.common.properties.EObjectSelectionProviderSection;
import org.bonitasoft.studio.common.properties.AbstractBonitaDescriptionSection;
import org.bonitasoft.studio.contract.core.validation.ContractDefinitionValidator;
import org.bonitasoft.studio.contract.i18n.Messages;
import org.bonitasoft.studio.contract.ui.property.constraint.ContractConstraintController;
......@@ -41,25 +41,27 @@ import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.databinding.EMFDataBindingContext;
import org.eclipse.emf.databinding.EMFObservables;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.databinding.swt.ISWTObservableValue;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.jface.databinding.viewers.ViewersObservables;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbenchPart;
/**
* @author Romain Bioteau
*
*/
public class ContractPropertySection extends EObjectSelectionProviderSection {
public class ContractPropertySection extends AbstractBonitaDescriptionSection {
private EMFDataBindingContext context;
......@@ -69,6 +71,11 @@ public class ContractPropertySection extends EObjectSelectionProviderSection {
private ContractConstraintController constraintController;
@Inject
private TaskAdaptableSelectionProvider selectionProvider;
private NewFormContributionItem newFormContributionItem;
@Override
public String getSectionDescription() {
return Messages.contractSectionDescription;
......@@ -85,6 +92,20 @@ public class ContractPropertySection extends EObjectSelectionProviderSection {
setInputController(new ContractInputController(getContractDefinitionValidator()));
setConstraintController(new ContractConstraintController(getContractDefinitionValidator()));
setContext(new EMFDataBindingContext());
newFormContributionItem = new NewFormContributionItem(ViewersObservables.observeSingleSelection(selectionProvider));
}
@Override
protected void updateToolbar(final IToolBarManager toolbarManager) {
toolbarManager.add(new NewFormContributionItem(ViewersObservables.observeSingleSelection(selectionProvider)));
}
@Override
public void refresh() {
super.refresh();
for (final IContributionItem object : form.getToolBarManager().getItems()) {
object.update();
}
}
@Override
......@@ -94,7 +115,8 @@ public class ContractPropertySection extends EObjectSelectionProviderSection {
tabFolder.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
getWidgetFactory().adapt(tabFolder, true, true);
final IObservableValue observeContractValue = CustomEMFEditObservables.observeDetailValue(Realm.getDefault(), getEObjectObservable(),
final IObservableValue observeContractValue = CustomEMFEditObservables.observeDetailValue(Realm.getDefault(),
ViewersObservables.observeSingleSelection(selectionProvider),
ProcessPackage.Literals.TASK__CONTRACT);
observeContractValue.addValueChangeListener(new IValueChangeListener() {
......@@ -137,7 +159,6 @@ public class ContractPropertySection extends EObjectSelectionProviderSection {
constraintsTableViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(500, 180).create());
constraintsTableViewer.initialize(getConstraintController(), getContractDefinitionValidator());
constraintsTableViewer.setInput(CustomEMFEditObservables.observeDetailList(Realm.getDefault(), observeContractValue,
ProcessPackage.Literals.CONTRACT__CONSTRAINTS));
constraintsTableViewer.createAddListener(addButton);
......@@ -198,6 +219,7 @@ public class ContractPropertySection extends EObjectSelectionProviderSection {
}
});
}
protected void bindRemoveButtonEnablement(final Button button, final Viewer viewer) {
getContext().bindValue(SWTObservables.observeEnabled(button),
ViewersObservables.observeSingleSelection(viewer),
......@@ -235,7 +257,7 @@ public class ContractPropertySection extends EObjectSelectionProviderSection {
private UpdateValueStrategy emptySelectionToBooleanStrategy() {
final UpdateValueStrategy modelStrategy = new UpdateValueStrategy();
modelStrategy.setConverter(new Converter(Object.class,Boolean.class) {
modelStrategy.setConverter(new Converter(Object.class, Boolean.class) {
@Override
public Object convert(final Object from) {
......@@ -309,11 +331,16 @@ public class ContractPropertySection extends EObjectSelectionProviderSection {
return modelStrategy;
}
@Override
public void setInput(final IWorkbenchPart part, final ISelection selection) {
super.setInput(part, selection);
selectionProvider.setSelection(selection);
}
protected void validate(final Contract contract) {
getContractDefinitionValidator().validate(contract);
}
public ContractDefinitionValidator getContractDefinitionValidator() {
return contractDefinitionValidator;
}
......
/**
* Copyright (C) 2014 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.contract.ui.property;
import static org.assertj.core.util.Strings.isNullOrEmpty;
import org.bonitasoft.studio.common.ExpressionConstants;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.contract.ContractPlugin;
import org.bonitasoft.studio.contract.i18n.Messages;
import org.bonitasoft.studio.model.expression.Expression;
import org.bonitasoft.studio.model.expression.ExpressionPackage;
import org.bonitasoft.studio.model.expression.provider.ExpressionItemProvider;
import org.bonitasoft.studio.model.expression.provider.ExpressionItemProviderAdapterFactory;
import org.bonitasoft.studio.model.process.FormMapping;
import org.bonitasoft.studio.model.process.ProcessPackage;
import org.bonitasoft.studio.model.process.Task;
import org.bonitasoft.studio.model.process.provider.FormMappingItemProvider;
import org.bonitasoft.studio.model.process.provider.ProcessItemProviderAdapterFactory;
import org.bonitasoft.studio.pagedesigner.core.expression.CreateNewFormProposalListener;
import org.bonitasoft.studio.pagedesigner.core.repository.WebPageFileStore;
import org.bonitasoft.studio.pagedesigner.core.repository.WebPageRepositoryStore;
import org.bonitasoft.studio.pics.Pics;
import org.bonitasoft.studio.preferences.BonitaStudioPreferencesPlugin;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IContributionManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.CoolBar;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.PlatformUI;
/**
* @author Romain Bioteau
*/
public class NewFormContributionItem implements IContributionItem {
private final IObservableValue selectionObservableValue;
private ToolItem toolItem;
public NewFormContributionItem(final IObservableValue selectionObservableValue) {
this.selectionObservableValue = selectionObservableValue;
}
@Override
public void update(final String arg0) {
}
@Override
public void update() {
if (toolItem != null) {
toolItem.setEnabled(isEnabled());
}
}
@Override
public void setVisible(final boolean arg0) {
}
@Override
public void setParent(final IContributionManager arg0) {
}
@Override
public void saveWidgetState() {
}
@Override
public boolean isVisible() {
return true;
}
@Override
public boolean isSeparator() {
return false;
}
@Override
public boolean isGroupMarker() {
return false;
}
@Override
public boolean isEnabled() {
final Task task = (Task) selectionObservableValue.getValue();
if (task != null) {
final FormMapping formMapping = task.getFormMapping();
return formMapping.isExternal() ? isNullOrEmpty(formMapping.getUrl()) : !formMapping.getTargetForm().hasName();
}
return false;
}
@Override
public boolean isDynamic() {
return false;
}
@Override
public boolean isDirty() {
return false;
}
@Override
public String getId() {
return null;
}
@Override
public void fill(final CoolBar arg0, final int arg1) {
}
@Override
public void fill(final ToolBar toolbar, final int arg1) {
toolItem = new ToolItem(toolbar, SWT.LEFT | SWT.PUSH | SWT.NO_FOCUS);
toolItem.setEnabled(false);
toolItem.setToolTipText(Messages.newFormTooltip);
toolItem.setImage(Pics.getImage("new_form.png", ContractPlugin.getDefault()));
final CreateNewFormProposalListener createNewFormProposalListener = new CreateNewFormProposalListener(
InstanceScope.INSTANCE.getNode(BonitaStudioPreferencesPlugin.PLUGIN_ID), PlatformUI.getWorkbench().getProgressService());
toolItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
final Task task = (Task) selectionObservableValue.getValue();
final String newPageId = createNewFormProposalListener.handleEvent(task.getFormMapping(), null);
final ExpressionItemProvider expressionItemProvider = new ExpressionItemProvider(new ExpressionItemProviderAdapterFactory());
final RepositoryAccessor repositoryAccessor = getRepositoryAccessor();
final WebPageRepositoryStore repositoryStore = repositoryAccessor.getRepositoryStore(WebPageRepositoryStore.class);
repositoryStore.refresh();
final WebPageFileStore webPageFileStore = repositoryStore.getChild(newPageId + ".json");
if (webPageFileStore != null) {
final Expression targetForm = task.getFormMapping().getTargetForm();
expressionItemProvider.setPropertyValue(targetForm,
ExpressionPackage.Literals.EXPRESSION__NAME.getName(), webPageFileStore.getDisplayName());
expressionItemProvider.setPropertyValue(targetForm,
ExpressionPackage.Literals.EXPRESSION__CONTENT.getName(), newPageId);
expressionItemProvider.setPropertyValue(targetForm,
ExpressionPackage.Literals.EXPRESSION__TYPE.getName(), ExpressionConstants.FORM_REFERENCE_TYPE);
expressionItemProvider.setPropertyValue(targetForm,
ExpressionPackage.Literals.EXPRESSION__RETURN_TYPE.getName(), String.class.getName());
expressionItemProvider.setPropertyValue(targetForm,
ExpressionPackage.Literals.EXPRESSION__RETURN_TYPE_FIXED.getName(), true);
final FormMappingItemProvider formMappingItemProvider = new FormMappingItemProvider(new ProcessItemProviderAdapterFactory());
formMappingItemProvider.setPropertyValue(task.getFormMapping(), ProcessPackage.Literals.FORM_MAPPING__EXTERNAL.getName(), false);
toolItem.setEnabled(false);
}
}
});
}
protected RepositoryAccessor getRepositoryAccessor() {
final RepositoryAccessor repositoryAccessor = new RepositoryAccessor();
repositoryAccessor.init();
return repositoryAccessor;
}
@Override
public void fill(final Menu parent, final int index) {
}
@Override
public void fill(final Composite arg0) {
}
@Override
public void dispose() {
}
}
/**
* Copyright (C) 2014 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.contract.ui.property;
import org.bonitasoft.studio.common.jface.selection.EObjectAdaptableSelectionProvider;
import org.bonitasoft.studio.model.process.PageFlow;
import org.bonitasoft.studio.model.process.Task;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.e4.core.di.annotations.Creatable;
import org.eclipse.emf.ecore.EObject;
/**
* @author Romain Bioteau
*/
@Creatable
public class TaskAdaptableSelectionProvider extends EObjectAdaptableSelectionProvider {
/*
* (non-Javadoc)
* @see org.bonitasoft.studio.pagedesigner.ui.part.AdaptableSelectionProvider#getAdapter(java.lang.Class)
*/
@SuppressWarnings("rawtypes")