Package tool.properties

Source Code of tool.properties.EventPropertyPage

package tool.properties;

import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeansObservables;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.map.IObservableMap;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
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.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchPropertyPage;
import org.eclipse.ui.dialogs.PropertyPage;

import tool.model.ToolEvent;
import tool.model.ToolParameter;

public class EventPropertyPage extends PropertyPage implements IWorkbenchPropertyPage{
  private DataBindingContext m_bindingContext;
 
  private ToolEvent event;
  private Composite body;
  private Text nameText;
  private Table parametersTable;
  private Button btnPublic;
  private TableViewer tableViewer;
  private TableColumn tblclmnCopyColumn;
  private TableViewerColumn tableViewerColumn_3;
  private TableColumn tblclmnParsingColumn;
  private TableViewerColumn tableViewerColumn_4;
 
 
  public EventPropertyPage() {
    super();
  }
  @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);
    lblName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblName.setText("Name");
   
    nameText = new Text(body, SWT.BORDER);
    nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    new Label(body, SWT.NONE);
   
    btnPublic = new Button(body, SWT.CHECK);
    btnPublic.setText("Public");
    new Label(body, SWT.NONE);
   
    tableViewer = new TableViewer(body, SWT.BORDER | SWT.FULL_SELECTION);
    parametersTable = tableViewer.getTable();
    parametersTable.setHeaderVisible(true);
    parametersTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
   
    tableViewerColumn_3 = new TableViewerColumn(tableViewer, SWT.NONE);
    tblclmnCopyColumn = tableViewerColumn_3.getColumn();
    tblclmnCopyColumn.setWidth(42);
    tblclmnCopyColumn.setText("Copy");
   
    TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    TableColumn tblclmnName = tableViewerColumn.getColumn();
    tblclmnName.setWidth(100);
    tblclmnName.setText("Name");
   
    TableViewerColumn tableViewerColumn_1 = new TableViewerColumn(tableViewer, SWT.NONE);
    TableColumn tblclmnType = tableViewerColumn_1.getColumn();
    tblclmnType.setWidth(100);
    tblclmnType.setText("Type");
   
    tableViewerColumn_4 = new TableViewerColumn(tableViewer, SWT.NONE);
    tblclmnParsingColumn = tableViewerColumn_4.getColumn();
    tblclmnParsingColumn.setWidth(100);
    tblclmnParsingColumn.setText("Parsing");
   
    TableViewerColumn tableViewerColumn_2 = new TableViewerColumn(tableViewer, SWT.NONE);
    TableColumn tblclmnDefault = tableViewerColumn_2.getColumn();
    tblclmnDefault.setWidth(100);
    tblclmnDefault.setText("Default");
    m_bindingContext = initDataBindings();
    return body;
  }
  public ToolEvent getEvent() {
    return event;
  }
  public void setEvent(ToolEvent event) {
    this.event = event;
  }
 
  @Override
  public void setElement(IAdaptable element) {
    super.setElement(element);
    if (element != null && element instanceof ToolEvent){
      setEvent((ToolEvent)element);
    }
  }
  protected DataBindingContext initDataBindings() {
    DataBindingContext bindingContext = new DataBindingContext();
    //
    IObservableValue nameTextObserveTextObserveWidget = SWTObservables.observeText(nameText, SWT.Modify);
    IObservableValue eventNameObserveValue = BeansObservables.observeValue(event, "toolName");
    bindingContext.bindValue(nameTextObserveTextObserveWidget, eventNameObserveValue, null, null);
    //
    IObservableValue btnPublicObserveSelectionObserveWidget = SWTObservables.observeSelection(btnPublic);
    IObservableValue eventPublicObserveValue = BeansObservables.observeValue(event, "public");
    bindingContext.bindValue(btnPublicObserveSelectionObserveWidget, eventPublicObserveValue, null, null);
    //
    ObservableListContentProvider listContentProvider = new ObservableListContentProvider();
    tableViewer.setContentProvider(listContentProvider);
    //
    IObservableMap[] observeMaps = BeansObservables.observeMaps(listContentProvider.getKnownElements(), ToolParameter.class, new String[]{"name", "type", "defaultValue"});
    tableViewer.setLabelProvider(new ObservableMapLabelProvider(observeMaps));
    //
    IObservableList eventParametersObserveList = BeansObservables.observeList(Realm.getDefault(), event, "parameters");
    tableViewer.setInput(eventParametersObserveList);
    //
    return bindingContext;
  }
}
TOP

Related Classes of tool.properties.EventPropertyPage

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.