Java tutorial
/** * Copyright (C) 2010 BonitaSoft S.A. * BonitaSoft, 31 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.properties.form.sections.options; import org.bonitasoft.studio.common.jface.BonitaStudioFontRegistry; import org.bonitasoft.studio.common.properties.ExtensibleGridPropertySection; import org.bonitasoft.studio.common.properties.IExtensibleGridPropertySectionContribution; import org.bonitasoft.studio.form.properties.i18n.Messages; import org.bonitasoft.studio.model.form.FormPackage; import org.bonitasoft.studio.model.form.Group; import org.bonitasoft.studio.model.form.Widget; import org.eclipse.core.databinding.DataBindingContext; import org.eclipse.emf.databinding.edit.EMFEditObservables; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.jface.databinding.swt.SWTObservables; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; /** * @author Baptiste Mesta * */ public class HtmlAttributesPropertySection implements IExtensibleGridPropertySectionContribution { private TransactionalEditingDomain editingDomain; private Widget widget; private DataBindingContext dataBinding; /* (non-Javadoc) * @see org.bonitasoft.studio.common.properties.IExtensibleGridPropertySectionContribution#createControl(org.eclipse.swt.widgets.Composite, org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory, org.bonitasoft.studio.common.properties.ExtensibleGridPropertySection) */ public void createControl(Composite composite, TabbedPropertySheetWidgetFactory widgetFactory, ExtensibleGridPropertySection extensibleGridPropertySection) { composite.setLayout(new GridLayout(1, false)); composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); if (dataBinding != null) { dataBinding.dispose(); } dataBinding = new DataBindingContext(); Text text = widgetFactory.createText(composite, "", SWT.MULTI | SWT.BORDER); GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, true); gd.heightHint = 80; text.setLayoutData(gd); dataBinding.bindValue(SWTObservables.observeText(text, SWT.Modify), EMFEditObservables .observeValue(editingDomain, widget, FormPackage.Literals.WIDGET__REAL_HTML_ATTRIBUTES)); /*Set an example beside*/ Label example = widgetFactory.createLabel(composite, Messages.OptionsSection_HtmlAttr_example, SWT.NONE); example.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1)); example.setFont(BonitaStudioFontRegistry.getCommentsFont()); } /* (non-Javadoc) * @see org.bonitasoft.studio.common.properties.IExtensibleGridPropertySectionContribution#dispose() */ public void dispose() { if (dataBinding != null) { dataBinding.dispose(); } } /* (non-Javadoc) * @see org.bonitasoft.studio.common.properties.IExtensibleGridPropertySectionContribution#getLabel() */ public String getLabel() { return Messages.OptionsSection_htmlAttribute; } /* (non-Javadoc) * @see org.bonitasoft.studio.common.properties.IExtensibleGridPropertySectionContribution#isRelevantFor(org.eclipse.emf.ecore.EObject) */ public boolean isRelevantFor(EObject eObject) { return eObject instanceof Widget && !(eObject instanceof Group); } /* (non-Javadoc) * @see org.bonitasoft.studio.common.properties.IExtensibleGridPropertySectionContribution#refresh() */ public void refresh() { } /* (non-Javadoc) * @see org.bonitasoft.studio.common.properties.IExtensibleGridPropertySectionContribution#setEObject(org.eclipse.emf.ecore.EObject) */ public void setEObject(EObject object) { this.widget = (Widget) object; } /* (non-Javadoc) * @see org.bonitasoft.studio.common.properties.IExtensibleGridPropertySectionContribution#setEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) */ public void setEditingDomain(TransactionalEditingDomain editingDomain) { this.editingDomain = editingDomain; } /* (non-Javadoc) * @see org.bonitasoft.studio.common.properties.IExtensibleGridPropertySectionContribution#setSelection(org.eclipse.jface.viewers.ISelection) */ public void setSelection(ISelection selection) { } }