Package tool.properties

Source Code of tool.properties.ConstantPropertyPage

package tool.properties;

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.IAdaptable;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.swt.SWT;
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.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchPropertyPage;
import org.eclipse.ui.dialogs.PropertyPage;

import tool.model.ToolConstant;

public class ConstantPropertyPage extends PropertyPage implements IWorkbenchPropertyPage{
  private DataBindingContext m_bindingContext;
  private Text nameText;
  private Text valueText;
  private ToolConstant constant;
  private Button publicCheckButton;
  private Composite body;
  /**
   * Create the form page.
   */
  public ConstantPropertyPage() {
    super();
  }


  /**
   * Create contents of the form.
   * @param managedForm
   */
  @Override
  protected Control createContents(Composite parent) {
    parent.setVisible(false);
    body = new Composite(parent, SWT.NONE);
   
    body.setLayout(new GridLayout(2, false));
    {
      Label lblName = new Label(body, SWT.NONE);
      GridData gd_lblName = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
      gd_lblName.widthHint = 36;
      lblName.setLayoutData(gd_lblName);
//      toolkit.adapt(lblName, true, true);
      lblName.setText("Name");
    }
    {
      nameText = new Text(body, SWT.BORDER);
      GridData gd_nameText = new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1);
      gd_nameText.widthHint = 211;
      nameText.setLayoutData(gd_nameText);
    }
    {
      Label lblValue = new Label(body, SWT.NONE);
      lblValue.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
      lblValue.setText("Value");
    }
    {
      valueText = new Text(body, SWT.BORDER);
      GridData gd_valueText = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
      gd_valueText.heightHint = 76;
      valueText.setLayoutData(gd_valueText);
    }
    new Label(body, SWT.NONE);
    {
      publicCheckButton = new Button(body, SWT.CHECK);
      publicCheckButton.setText("Public");
    }
    if (this.constant != null)
      m_bindingContext = initDataBindings();
   
    return body;
  }
  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 setElement(IAdaptable element) {
    super.setElement(element);
    if (element instanceof ToolConstant){
      setConstant((ToolConstant)element);
    }
}
}
TOP

Related Classes of tool.properties.ConstantPropertyPage

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.