Package de.innovationgate.eclipse.utils.ui

Source Code of de.innovationgate.eclipse.utils.ui.DynamicListControl

/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*     Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.utils.ui;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.jface.layout.GridDataFactory;
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.List;

public class DynamicListControl extends Composite {
 
  protected GridData _btnLayout;
  private Composite _buttonArea;
 
  protected Map<String, Button> _buttons = new HashMap<String, Button>();
  private String[] _items;
  private List _list;
 
  public static final String BUTTON_ADD = "BUTTON_ADD";
  public static final String BUTTON_REMOVE = "BUTTON_REMOVE"

  public DynamicListControl(Composite parent, int style) {
    super(parent, style);
  }
 
  public void init(String[] items) {
    _items = items;
    _btnLayout = new GridData(GridData.FILL, GridData.VERTICAL_ALIGN_FILL, true , false);
    createControls()
  }

  private void createControls() {
    GridLayout layout = new GridLayout();   
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    this.setLayout(layout);
   
   
    GridData fillBoth = new GridData(GridData.FILL_BOTH);
        fillBoth.minimumHeight = 100;
        fillBoth.verticalSpan = 2;
        _list = new org.eclipse.swt.widgets.List(this, SWT.BORDER|SWT.MULTI);
        _list.setLayoutData(fillBoth);
        _list.setItems(_items);
       
       
        _buttonArea = new Composite(this, SWT.NONE);
      layout = new GridLayout();   
    layout.numColumns = 1;
    layout.marginHeight = 0;
    layout.marginWidth = 0;           
    _buttonArea.setLayout(layout);
    _buttonArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
   
        createButtonArea(_buttonArea);
  }

  protected void createButtonArea(Composite area) {       
        Button btnAdd = new Button(area, SWT.PUSH);
        btnAdd.setText("add");
        btnAdd.setLayoutData(GridDataFactory.copyData(_btnLayout));
        btnAdd.pack();
        _buttons.put(BUTTON_ADD, btnAdd);
       
        Button btnRemove = new Button(area, SWT.PUSH);
        btnRemove.setText("remove");
        btnRemove.setLayoutData(GridDataFactory.copyData(_btnLayout));
        btnRemove.pack();
        _buttons.put(BUTTON_REMOVE, btnRemove);
 
 
  public Button getButton(String id) {
    return _buttons.get(id);
  }
 
  public void setItems(String[] items) {
    _items = items;
    _list.setItems(_items);
  }

  public List getList() {
    return _list;
  }
}
TOP

Related Classes of de.innovationgate.eclipse.utils.ui.DynamicListControl

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.