package ivasoft.mainwindow.urun;
import java.util.List;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;
import crud.UrunlerAnaCRUD;
import dao.UrunlerAnaDAO;
@SuppressWarnings("serial")
public class RemoveUrunUi extends VerticalLayout{
@SuppressWarnings("unchecked")
public RemoveUrunUi() {
setMargin(true);
setWidth("100%");
setHeight("500px");
System.out.println("delete");
final Table table = new Table();
table.setWidth("470px");
table.setHeight("500px");
table.setImmediate(true);
table.setSelectable(true);
UrunlerAnaCRUD urunlerAnaCRUD = new UrunlerAnaCRUD();
table.addContainerProperty("Ürün Kodu", String.class, null);
table.addContainerProperty("Ürün Adı", String.class, null);
table.addContainerProperty("Ürün Markası", String.class, null);
table.addContainerProperty("Ürün Modeli", String.class, null);
List<UrunlerAnaDAO> array = urunlerAnaCRUD.findAllUrunAna();
ComboBox urunAdıFilterCombo = new ComboBox("Ürün Adı");
ComboBox urunKoduFilterCombo = new ComboBox("Ürün Kodu");
ComboBox urunMarkasiFilterCombo = new ComboBox("Ürün Markası");
ComboBox urunModeliFilterCombo = new ComboBox("Ürün Modeli");
urunAdıFilterCombo.addItem("Tüm Ürünler");
urunKoduFilterCombo.addItem("Tüm Ürünler");
urunMarkasiFilterCombo.addItem("Tüm Ürünler");
urunModeliFilterCombo .addItem("Tüm Ürünler");
for (int i = 0; i < array.size(); i++) {
if(array.get(i).getUrunAdi()!=null){
urunAdıFilterCombo.addItem(array.get(i).getUrunAdi());
}if (array.get(i).getUrunKodu()!=null) {
urunKoduFilterCombo.addItem(array.get(i).getUrunKodu());
}if (array.get(i).getUrunMarka()!=null) {
urunMarkasiFilterCombo.addItem(array.get(i).getUrunMarka());
}if (array.get(i).getUrunModel()!=null) {
urunModeliFilterCombo.addItem(array.get(i).getUrunModel());
}
table.addItem(new Object[] {array.get(i).getUrunKodu(),
array.get(i).getUrunAdi(),
array.get(i).getUrunMarka(),
array.get(i).getUrunModel()}, new Integer(i+1));
}
table.setColumnReorderingAllowed(true);
table.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_HIDDEN);
final int urunAdiWidth = 90;
final int urunKoduWidth = 200;
final int urunMarkaWidth = 90;
final int urunModelWidth = 90;
table.setColumnWidth("Ürün Kodu", urunAdiWidth);
table.setColumnWidth("Ürün Adı", urunKoduWidth);
table.setColumnWidth("Ürün Markası", urunMarkaWidth);
table.setColumnWidth("Ürün Modeli", urunModelWidth);
urunAdıFilterCombo.setWidth(urunKoduWidth + 2*6, Sizeable.UNITS_PIXELS);
urunKoduFilterCombo.setWidth(urunAdiWidth+2*6, Sizeable.UNITS_PIXELS);
urunMarkasiFilterCombo.setWidth(urunMarkaWidth +2*6, Sizeable.UNITS_PIXELS);
urunModeliFilterCombo.setWidth(urunModelWidth +2*6, Sizeable.UNITS_PIXELS);
//urunAdıFilterCombo.addItem("Tüm Ürünler");
urunKoduFilterCombo.setNullSelectionItemId("Tüm Ürünler");
urunKoduFilterCombo.setInputPrompt("Tüm Ürünler");
urunKoduFilterCombo.setImmediate(true);
urunKoduFilterCombo.addListener(new Property.ValueChangeListener() {
public void valueChange(ValueChangeEvent event) {
IndexedContainer container = (IndexedContainer) table.getContainerDataSource();
String filter = (String) event.getProperty().getValue();
if (filter == null) {
container.removeContainerFilters("Ürün Kodu");
return;
}
// Set the filter
container.removeContainerFilters("Ürün Kodu");
container.addContainerFilter("Ürün Kodu", filter, true, true);
}
});
urunModeliFilterCombo.setNullSelectionItemId("Tüm Ürünler");
urunModeliFilterCombo.setInputPrompt("Tüm Ürünler");
urunModeliFilterCombo.setImmediate(true);
urunModeliFilterCombo.addListener(new Property.ValueChangeListener() {
public void valueChange(ValueChangeEvent event) {
IndexedContainer container = (IndexedContainer) table.getContainerDataSource();
String filter = (String) event.getProperty().getValue();
if (filter == null) {
container.removeContainerFilters("Ürün Modeli");
return;
}
// Set the filter
container.removeContainerFilters("Ürün Modeli");
container.addContainerFilter("Ürün Modeli", filter, true, true);
}
});
urunMarkasiFilterCombo.setNullSelectionItemId("Tüm Ürünler");
urunMarkasiFilterCombo.setInputPrompt("Tüm Ürünler");
urunMarkasiFilterCombo.setImmediate(true);
urunMarkasiFilterCombo.addListener(new Property.ValueChangeListener() {
public void valueChange(ValueChangeEvent event) {
IndexedContainer container = (IndexedContainer) table.getContainerDataSource();
String filter = (String) event.getProperty().getValue();
if (filter == null) {
container.removeContainerFilters("Ürün Markası");
return;
}
// Set the filter
container.removeContainerFilters("Ürün Markası");
container.addContainerFilter("Ürün Markası", filter, true, true);
}
});
urunAdıFilterCombo.setNullSelectionItemId("Tüm Ürünler");
urunAdıFilterCombo.setInputPrompt("Tüm Ürünler");
urunAdıFilterCombo.setImmediate(true);
urunAdıFilterCombo.addListener(new Property.ValueChangeListener() {
public void valueChange(ValueChangeEvent event) {
IndexedContainer container = (IndexedContainer) table.getContainerDataSource();
String filter = (String) event.getProperty().getValue();
if (filter == null) {
container.removeContainerFilters("Ürün Adı");
return;
}
// Set the filter
container.removeContainerFilters("Ürün Adı");
container.addContainerFilter("Ürün Adı", filter, true, true);
}
});
GridLayout tableHeader = new GridLayout(6,2);
tableHeader.addStyleName("fakeheader");
tableHeader.addComponent(urunKoduFilterCombo, 0, 0);
tableHeader.addComponent(urunAdıFilterCombo, 1, 0);
tableHeader.addComponent(urunMarkasiFilterCombo, 2, 0);
tableHeader.addComponent(urunModeliFilterCombo, 3, 0);
addComponent(tableHeader);
addComponent(table);
}
}