Package tool.editors.cdf

Source Code of tool.editors.cdf.ConstantDialog

package tool.editors.cdf;

import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.beans.BeansObservables;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.ResourceManager;

import tool.model.ToolConstant;
import tool.model.validation.ToolNameValidator;

public class ConstantDialog extends TitleAreaDialog {
  private DataBindingContext m_bindingContext;
  private Text nameText;
  private Text valueText;
  ToolConstant constant;
  private Button button;
  private Combo typeCombo;

  public static int show(ToolConstant constant){
    Shell shell = Display.getDefault().getActiveShell();
    ConstantDialog dialog = new ConstantDialog(shell, constant);
    return dialog.open();
  }
  private ConstantDialog(Shell parentShell, ToolConstant constant) {
    super(parentShell);
    this.constant = constant;
  }

  /**
   * Create contents of the dialog.
   * @param parent
   */
  @Override
  protected Control createDialogArea(Composite parent) {
    setMessage("Edit Constant properties");
    setTitleImage(ResourceManager.getPluginImage("Tool", "icons/constant.gif"));
    setTitle("Constant");
    Composite area = (Composite) super.createDialogArea(parent);
    Composite container = new Composite(area, SWT.NONE);
    container.setLayout(new GridLayout(2, false));
    container.setLayoutData(new GridData(GridData.FILL_BOTH));
   
    Label label = new Label(container, SWT.NONE);
    label.setText("Name");
   
    nameText = new Text(container, SWT.BORDER);
    nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
   
    Label label_1 = new Label(container, SWT.NONE);
    label_1.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
    label_1.setText("Value");
   
    valueText = new Text(container, SWT.BORDER | SWT.V_SCROLL);
    GridData gd_valueText = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    gd_valueText.heightHint = 64;
    gd_valueText.widthHint = 362;
    valueText.setLayoutData(gd_valueText);
   
    Label lblType = new Label(container, SWT.NONE);
    lblType.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblType.setText("Type");
   
    typeCombo = new Combo(container, SWT.NONE);
    GridData gd_typeCombo = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_typeCombo.minimumWidth = 90;
    gd_typeCombo.widthHint = 90;
    typeCombo.setLayoutData(gd_typeCombo);
    typeCombo.setVisibleItemCount(5);
    typeCombo.setItems(new String[] {"Automatic", "Boolean", "Double", "Integer", "String"});
    typeCombo.select(0);
    new Label(container, SWT.NONE);
   
    button = new Button(container, SWT.CHECK);
    button.setText("Public");

    return area;
  }

  /**
   * Create contents of the button bar.
   * @param parent
   */
  @Override
  protected void createButtonsForButtonBar(Composite parent) {
    createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
        true);
    createButton(parent, IDialogConstants.CANCEL_ID,
        IDialogConstants.CANCEL_LABEL, false);
    m_bindingContext = initDataBindings();
  }

  /**
   * Return the initial size of the dialog.
   */
  @Override
  protected Point getInitialSize() {
    return new Point(450, 298);
  }

  public ToolConstant getConstant() {
    return constant;
  }

  public void setConstant(ToolConstant constant) {
    this.constant = constant;
    m_bindingContext = initDataBindings();
  }
  protected DataBindingContext initDataBindings() {
    DataBindingContext bindingContext = new DataBindingContext();
    //
    IObservableValue textObserveTextObserveWidget = SWTObservables.observeText(nameText, SWT.Modify);
    IObservableValue constantNameObserveValue = BeansObservables.observeValue(constant, "toolName");
    UpdateValueStrategy strategy = new UpdateValueStrategy();
    strategy.setAfterConvertValidator(new ToolNameValidator(nameText));
    bindingContext.bindValue(textObserveTextObserveWidget, constantNameObserveValue, strategy, null);
    //
    IObservableValue text_1ObserveTextObserveWidget = SWTObservables.observeText(valueText, SWT.Modify);
    IObservableValue constantValueObserveValue = BeansObservables.observeValue(constant, "value");
    bindingContext.bindValue(text_1ObserveTextObserveWidget, constantValueObserveValue, null, null);
    //
    IObservableValue buttonObserveVisibleObserveWidget = SWTObservables.observeVisible(button);
    IObservableValue constantClassConstantObserveValue = BeansObservables.observeValue(constant, "classConstant");
    bindingContext.bindValue(buttonObserveVisibleObserveWidget, constantClassConstantObserveValue, null, null);
    //
    IObservableValue buttonObserveSelectionObserveWidget = SWTObservables.observeSelection(button);
    IObservableValue constantPublicObserveValue = BeansObservables.observeValue(constant, "public");
    bindingContext.bindValue(buttonObserveSelectionObserveWidget, constantPublicObserveValue, null, null);
    //
    IObservableValue buttonObserveVisibleObserveWidget_1 = SWTObservables.observeVisible(button);
    IObservableValue constantReadWriteObserveValue = BeansObservables.observeValue(constant, "readWrite");
    bindingContext.bindValue(buttonObserveVisibleObserveWidget_1, constantReadWriteObserveValue, null, null);
    //
    IObservableValue typeComboObserveSelectionObserveWidget = SWTObservables.observeSelection(typeCombo);
    IObservableValue constantTypeObserveValue = BeansObservables.observeValue(constant, "type");
    bindingContext.bindValue(typeComboObserveSelectionObserveWidget, constantTypeObserveValue, null, null);
    //
    return bindingContext;
  }
}
TOP

Related Classes of tool.editors.cdf.ConstantDialog

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.