Package tool.properties

Source Code of tool.properties.AttributePropertyPage

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.ToolAttribute;

public class AttributePropertyPage extends PropertyPage implements IWorkbenchPropertyPage{
  private DataBindingContext m_bindingContext;
  private Text nameText;
  private Text typeText;
  private Button btnCheckButton;
  private Button lookupButton;
  private ToolAttribute attribute;
  public AttributePropertyPage(){
    super();
  }

  @Override
  protected Control createContents(Composite parent) {
    parent.setVisible(false);
    Composite myComposite = new Composite(parent, SWT.NONE);
    GridLayout mylayout = new GridLayout();
    mylayout.numColumns = 3;
    mylayout.marginHeight = 1;
    mylayout.marginWidth = 1;
    myComposite.setLayout(mylayout);
    Label nameLabel = new Label(myComposite, SWT.NONE);
    nameLabel.setText("Name");
    nameText = new Text(myComposite, SWT.BORDER);
    nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    nameText.setText("");
    new Label(myComposite, SWT.NONE);
   
    Label lblType = new Label(myComposite, SWT.NONE);
    lblType.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblType.setText("Type");
   
    typeText = new Text(myComposite, SWT.BORDER);
    typeText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
   
    lookupButton = new Button(myComposite, SWT.NONE);
    lookupButton.setText("...");
    new Label(myComposite, SWT.NONE);
   
    btnCheckButton = new Button(myComposite, SWT.CHECK);
    btnCheckButton.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, false, false, 1, 1));
    btnCheckButton.setText("Public");
    new Label(myComposite, SWT.NONE);
    m_bindingContext = initDataBindings();
    return myComposite;
  }
  @Override
  public boolean performOk() {
    return super.performOk();
  }

  public ToolAttribute getAttribute() {
    return attribute;
  }

  public void setAttribute(ToolAttribute attribute) {
    this.attribute = attribute;
  }
  @Override
  public void setElement(IAdaptable element) {
    super.setElement(element);
    if (element instanceof ToolAttribute){
      setAttribute((ToolAttribute)element);
    }
  }
  protected DataBindingContext initDataBindings() {
    DataBindingContext bindingContext = new DataBindingContext();
    //
    IObservableValue nameTextObserveTextObserveWidget = SWTObservables.observeText(nameText, SWT.Modify);
    IObservableValue attributeNameObserveValue = BeansObservables.observeValue(attribute, "toolName");
    bindingContext.bindValue(nameTextObserveTextObserveWidget, attributeNameObserveValue, null, null);
    //
    IObservableValue typeTextObserveTextObserveWidget = SWTObservables.observeText(typeText, SWT.Modify);
    IObservableValue attributeTypeObserveValue = BeansObservables.observeValue(attribute, "type");
    bindingContext.bindValue(typeTextObserveTextObserveWidget, attributeTypeObserveValue, null, null);
    //
    IObservableValue btnCheckButtonObserveSelectionObserveWidget = SWTObservables.observeSelection(btnCheckButton);
    IObservableValue attributePublicObserveValue = BeansObservables.observeValue(attribute, "public");
    bindingContext.bindValue(btnCheckButtonObserveSelectionObserveWidget, attributePublicObserveValue, null, null);
    //
    return bindingContext;
  }
}
TOP

Related Classes of tool.properties.AttributePropertyPage

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.