public int searchForm() {
    // 1. Remove filter dan Refresh container dalulu dahulu
    model.reload();
    model.getBeanItemContainerHeader().removeAllContainerFilters();

    // 2. Baru Kasih Filter Lagi
    //		String theRefno = view.getFieldSearchByRefno().getValue().toString().trim();
    String theId = view.getFieldSearchById().getValue().toString().trim();
    String theDesc = view.getFieldSearchByDesc().getValue().toString().trim();

    //		Filter filter1 = new SimpleStringFilter("refno", theRefno, true, false);
    Filter filter2 = new Or(new SimpleStringFilter("custno", theId, true, false));
    Filter filter3 = new Or(new SimpleStringFilter("custname", theDesc, true, false));
    //		model.getBeanItemContainerBukugiro().addContainerFilter(filter1);
    model.getBeanItemContainerHeader().addContainerFilter(filter2);
    model.getBeanItemContainerHeader().addContainerFilter(filter3);

    // 3. Refresh TABLE
    view.setDisplay();
    view.getTable().refreshRowCache();
    // 4. Focus KE TABLE
    view.getTable().focus();

    return 0;
  }
  public int updateAndValidateForm() {
    try {
      // 3.2 Masukkan nilai form yang valid(commit) ke dalam tabel >> dan database
      model.getBinderHeader().commit();
      model.getsMerkJpaService().updateObject(model.getItemHeader());

      view.getTable().refreshRowCache();

      // 3.3. atur kondisi status form
      view.setDisplay();
      model.setOperationStatus(EnumOperationStatus.EDITING.getStrCode());
      view.setFormButtonAndTextState();
      // 3.4. Refresh lagi container >> SUDAH TIDAK DIPERLUKAN LAGI OLEH KARENA OPERSI //3.2

      Notification.show("UPDATE Sukses!!!", Notification.TYPE_TRAY_NOTIFICATION);
      try {
        view.getTable().focus();
      } catch (Exception ex) {
      }

    } catch (Exception ex) {
      Notification.show("Terjadi Kesalahan Insert data!!!", Notification.TYPE_TRAY_NOTIFICATION);
      view.focustIdOrDesc();
      return 1;
    }
    return 0;
  }
  public int insertAndValidateForm() {
    boolean kodeValid = true;
    boolean inputValid = true;
    String theId = (String) view.getFieldId().getConvertedValue();

    if (theId.trim().equalsIgnoreCase("New")) {
      kodeValid = false;
      Notification.show("ID tidak boleh New!!", Notification.TYPE_TRAY_NOTIFICATION);
      view.focustIdOrDesc();
      return 1;
    }

    //		//VALIDASI KODE TIDAK DIPERLUKAN LAGI
    //		if (model.getfAreaJpaService().findAll(theId).size()>0){
    //			kodeValid = false;
    //			Notification.show("Kode Sudah Terpakai!!.");
    //			view.focustIdOrDesc();
    //			return 1;
    //		}

    // 2. Additional Validasi input di handle oleh form Validator
    // 3. Aksi Save
    if (kodeValid && inputValid) {
      try {
        // 3.1 commit form >> MASUKKAN KE DATABASE
        model.getBinderHeader().commit(); // COMMIT TETAP PAKE NEW TAPI CLIENT SIDE

        model.getsMerkJpaService().createObject(model.getNewItemHeader());

        // 3.2 Masukkan nilai form yang valid(commit) ke dalam tabel
        model.getBeanItemContainerHeader().addItem(model.getNewItemHeader());
        view.getTable().refreshRowCache();

        // 3.3. atur kondisi status form
        view.setDisplay();
        model.setOperationStatus(EnumOperationStatus.OPEN.getStrCode());
        view.setFormButtonAndTextState();
        // 3.4. Refresh lagi container >> SUDAH TIDAK DIPERLUKAN LAGI OLEH KARENA OPERSI //3.2

        Notification.show("Penambahan Sukses!!!", Notification.TYPE_TRAY_NOTIFICATION);
        try {
          view.getTable().focus();
        } catch (Exception ex) {
        }

      } catch (Exception ex) {
        Notification.show("Terjadi Kesalahan Insert data!!!", Notification.TYPE_TRAY_NOTIFICATION);
        view.focustIdOrDesc();
        ex.printStackTrace();
        return 1;
      }
    } else {
      return 2;
    }

    return 0;
  }
  public void deleteForm() {
    final Object itemId = view.getTable().getValue();

    if (itemId != null) {
      ConfirmDialog.Listener konfirmDialogListener =
          new ConfirmDialog.Listener() {
            @Override
            public void onClose(ConfirmDialog dialog) {
              if (dialog.isConfirmed()) {
                // Confirmed to continue
                try {
                  model.getsMerkJpaService().removeObject(model.getItemHeader());

                  model.getBeanItemContainerHeader().removeItem(itemId);

                  view.getTable().refreshRowCache();
                  view.setDisplay();
                  Notification.show("Delete Sukses", Notification.TYPE_TRAY_NOTIFICATION);
                } catch (Exception ex) {
                  Notification.show("Error Delete!!", Notification.TYPE_TRAY_NOTIFICATION);
                }
              } else {
                // User did not confirm
              }
              view.getTable().focus();
            }
          };

      final ConfirmDialog d =
          ConfirmDialog.show(
              view.getUI(),
              "Konfirmasi Hapus",
              "Yakin akan hapus data?",
              "Oke Delete..",
              "Cancel",
              konfirmDialogListener);

      final ShortcutListener enter =
          new ShortcutListener("Oke", KeyCode.ENTER, null) {
            @Override
            public void handleAction(Object sender, Object target) {
              d.close();
            }
          };

      d.setStyleName("dialog");
      d.getOkButton().setStyleName("small");
      d.getCancelButton().setStyleName("small");
      d.focus();

    } else {
      Notification.show("Tidak ada yang dipilih!!!", Notification.TYPE_TRAY_NOTIFICATION);
    }
  }
  public void initListener() {
    view.getBtnNewForm().addClickListener(this);
    view.getBtnEditForm().addClickListener(this);
    view.getBtnCancelForm().addClickListener(this);
    view.getBtnDeleteForm().addClickListener(this);
    view.getBtnHelp().addClickListener(this);
    view.getBtnPrint().addClickListener(this);
    view.getBtnSaveForm().addClickListener(this);
    view.getBtnSearch().addClickListener(this);

    view.getBtnUtility().addClickListener(this);

    view.getTable().addItemClickListener(this);
  }
  @Override
  public void itemClick(ItemClickEvent event) {
    Object itemId = event.getItemId();
    Item item = view.getTable().getItem(itemId);
    boolean entitySelected = item != null;
    // modify visibility of form and delete button if an item is selected
    view.getFormLayout().setVisible(entitySelected);
    view.getBtnDeleteForm().setEnabled(entitySelected);

    if (entitySelected) {

      model.itemHeader = new SMerk();
      model.itemHeader = model.getBeanItemContainerHeader().getItem(itemId).getBean();
      model.getBinderHeader().setItemDataSource(model.itemHeader);

      if (event.isDoubleClick()) {
        view.showWindowForm();
      }
    }

    view.bindAndBuildFieldGroupComponent();
    model.setOperationStatus(EnumOperationStatus.EDITING.getStrCode());
    view.setFormButtonAndTextState();
  }
  @Override
  public void buttonClick(ClickEvent event) {
    // TODO Auto-generated method stub
    // Antisipasi
    if (model.getOperationStatus() == null)
      model.setOperationStatus(EnumOperationStatus.OPEN.getStrCode());
    if (model.getOperationStatus().equals(""))
      model.setOperationStatus(EnumOperationStatus.OPEN.getStrCode());

    if (event.getButton() == view.getBtnNewForm()) {
      addItem();
      view.showWindowForm();
    } else if (event.getButton() == view.getBtnEditForm()) {
      view.showWindowForm();
    } else if (event.getButton() == view.getBtnDeleteForm()) {
      deleteForm();
    } else if (event.getButton() == view.getBtnSaveForm()) {
      ConfirmDialog commitDialog =
          ConfirmDialog.show(
              view.getUI(),
              "Konfirmasi Simpan",
              "Simpan Data?",
              "Save",
              "No",
              new ConfirmDialog.Listener() {
                public void onClose(ConfirmDialog dialog) {
                  if (dialog.isConfirmed()) {
                    // Confirmed to continue
                    try {
                      if (model
                          .getOperationStatus()
                          .equals(EnumOperationStatus.ADDING.getStrCode())) {
                        if (insertAndValidateForm() == 0) {
                          view.getTable().focus();
                          view.closeWindowForm();
                        } else {
                          view.focustIdOrDesc();
                        }
                      } else if (model
                          .getOperationStatus()
                          .equals(EnumOperationStatus.EDITING.getStrCode())) {
                        if (updateAndValidateForm() == 0) {
                          view.getTable().focus();
                          view.closeWindowForm();
                        } else {
                          view.focustIdOrDesc();
                        }
                      }

                    } catch (Exception ex) {
                      Notification.show("Terjadi Kesalahan Simpan");
                    }

                  } else {
                    view.focustIdOrDesc();
                  }
                }
              });
      commitDialog.setStyleName("dialog");
      commitDialog.getOkButton().setStyleName("small");
      commitDialog.getCancelButton().setStyleName("small");
      // Jangan lupa
      commitDialog.focus();

    } else if (event.getButton() == view.getBtnCancelForm()) {
      if (model.getOperationStatus().equals(EnumOperationStatus.ADDING.getStrCode())) {
        discardForm();
      } else if (model.getOperationStatus().equals(EnumOperationStatus.ADDING.getStrCode())
          || model.getOperationStatus().equals(EnumOperationStatus.EDITING.getStrCode())) {
        if (view.getFormLayout().isVisible()) {
          discardForm();
        }
      } else {
        view.getTable().focus();
      }

      //			discardForm(operationStatus);
    } else if (event.getButton() == view.getBtnSearch()) {
      searchForm();
    } else if (event.getButton() == view.getBtnPrint()) {
      printForm();
    } else if (event.getButton() == view.getBtnHelp()) {
      helpForm();
    } else if (event.getButton() == view.getBtnUtility()) {
      view.showWindowUtility();
    }
    // Tidak semua akan di refresh container nya >> Jadi refresh container tidak bisa di taruh
    // disini

  }