package tool.editors.cdf;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeansObservables;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.part.EditorPart;
import org.eclipse.wb.swt.ResourceManager;
import tool.ToolPlugin;
import tool.model.ToolConstant;
@Deprecated
public class ConstantEditor extends EditorPart {
private DataBindingContext m_bindingContext;
public static final String ID = "tool.editors.cdf.ConstantEditor"; //$NON-NLS-1$
private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
private Text nameText;
private Text valueText;
private ToolConstant constant;
private Button publicCheckButton;
public ConstantEditor() {
super();
setContentDescription("Tool Constant");
setPartName("Constant");
setTitleToolTip("Edit a constant");
setTitleImage(ResourceManager.getPluginImage("Tool", "icons/constant.gif"));
}
@Override
public void setInitializationData(IConfigurationElement cfig,
String propertyName, Object data) {
// TODO Auto-generated method stub
super.setInitializationData(cfig, propertyName, data);
// data.toString();
}
/**
* Create contents of the view part.
* @param parent
*/
@Override
public void createPartControl(Composite parent) {
Composite container = toolkit.createComposite(parent, SWT.NONE);
toolkit.paintBordersFor(container);
container.setLayout(new GridLayout(2, false));
{
Label lblName = new Label(container, SWT.NONE);
lblName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
toolkit.adapt(lblName, true, true);
lblName.setText("Name");
}
{
nameText = new Text(container, SWT.BORDER);
nameText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
toolkit.adapt(nameText, true, true);
}
{
Label lblValue = new Label(container, SWT.NONE);
lblValue.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
toolkit.adapt(lblValue, true, true);
lblValue.setText("Value");
}
{
valueText = new Text(container, SWT.BORDER);
GridData gd_valueText = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
gd_valueText.heightHint = 76;
valueText.setLayoutData(gd_valueText);
toolkit.adapt(valueText, true, true);
}
new Label(container, SWT.NONE);
{
publicCheckButton = new Button(container, SWT.CHECK);
toolkit.adapt(publicCheckButton, true, true);
publicCheckButton.setText("Public");
}
if (this.constant != null)
m_bindingContext = initDataBindings();
}
public void dispose() {
toolkit.dispose();
super.dispose();
}
@Override
public void setFocus() {
// Set the focus
}
public ToolConstant getConstant() {
return constant;
}
public void setConstant(ToolConstant constant) {
if (m_bindingContext != null){
m_bindingContext = null;
}
this.constant = constant;
if (this.constant != null && this.nameText != null){
m_bindingContext = initDataBindings();
}
}
protected DataBindingContext initDataBindings() {
DataBindingContext bindingContext = new DataBindingContext();
//
IObservableValue nameTextObserveTextObserveWidget = SWTObservables.observeText(nameText, SWT.Modify);
IObservableValue constantNameObserveValue = BeansObservables.observeValue(constant, "toolName");
bindingContext.bindValue(nameTextObserveTextObserveWidget, constantNameObserveValue, null, null);
//
IObservableValue valueTextObserveTextObserveWidget = SWTObservables.observeText(valueText, SWT.Modify);
IObservableValue constantValueObserveValue = BeansObservables.observeValue(constant, "value");
bindingContext.bindValue(valueTextObserveTextObserveWidget, constantValueObserveValue, null, null);
//
IObservableValue publicCheckButtonObserveSelectionObserveWidget = SWTObservables.observeSelection(publicCheckButton);
IObservableValue constantPublicObserveValue = BeansObservables.observeValue(constant, "public");
bindingContext.bindValue(publicCheckButtonObserveSelectionObserveWidget, constantPublicObserveValue, null, null);
//
return bindingContext;
}
@Override
public void doSave(IProgressMonitor arg0) {
// TODO Auto-generated method stub
}
@Override
public void doSaveAs() {
}
@Override
public void init(IEditorSite site, IEditorInput data)
throws PartInitException {
setSite(site);
setInput(data);
if (data instanceof ToolConstant)
this.setConstant((ToolConstant)data);
setPartName(data.getName());
}
@Override
public boolean isDirty() {
return false;
}
@Override
public boolean isSaveAsAllowed() {
return false;
}
@Override
public Image getTitleImage() {
return ToolPlugin.getImage("icons/private_constant.gif");
}
@Override
public String getTitleToolTip() {
return "Edit a Constant";
}
}