Example #1
0
  protected void append(BaseContainer e) {
    boolean ensureText = false;
    BaseContainer last = (BaseContainer) this.getChildAt(getChildCount() - 1);
    if (e instanceof NumberItem) {
      if (currentIndex == -1) {
        if (last instanceof NumberItem) {
          currentIndex = ((NumberItem) getChildAt(getChildCount() - 1)).getNum() + 1;
        } else {
          currentIndex = 1;
        }
      } else {
        currentIndex++;
      }
      ((NumberItem) e).setNum(currentIndex);

    } else {
      currentIndex = -1;
    }
    if ((!(getChildAt(getChildCount() - 1) instanceof Text)) && getChildCount() > 1) {
      ensureText = true;
    }
    if (ensureText) {
      this.addView(e);
      this.addView(new Text(getContext()));
    } else {
      if (getChildCount() > 1) {
        this.addView(e, getChildCount() - 1);
      } else {
        this.addView(e);
        this.addView(new Text(getContext()));
        e.focus();
      }
    }
  }
  @Override
  public void detectAndSendChanges() {
    super.detectAndSendChanges();
    byte isSending = (byte) (fluid.isSending ? 1 : 0);
    int fID = fluid.tank.getFluid() != null ? fluid.tank.getFluid().fluidID : -1,
        fAmt = fluid.tank.getFluidAmount();

    for (int i = 0; i < crafters.size(); i++) {
      ICrafting icrafting = (ICrafting) crafters.get(i);

      if (wasSending != isSending) {
        icrafting.sendProgressBarUpdate(this, 0, isSending);
      }

      if (fluidID != fID) {
        icrafting.sendProgressBarUpdate(this, 1, fID);
      }

      if (fluidAmt != fAmt) {
        icrafting.sendProgressBarUpdate(this, 2, fAmt);
      }

      wasSending = isSending;
      fluidID = fID;
      fluidAmt = fAmt;
    }
  }
Example #3
0
 public void requestNext(BaseContainer view) {
   BaseContainer container = (BaseContainer) view.getParent().getParent();
   if (container instanceof Todo) {
     int index = this.indexOfChild(container);
     this.addTodoOn(index + 1);
   }
   if (container instanceof Item) {
     int index = this.indexOfChild(container);
     this.addItemOn(index + 1);
   }
 }
  public boolean isRemoved(Object ejbRef) {

    EJBLocalObjectImpl localObjectImpl = getEJBLocalObject(ejbRef);

    if (localObjectImpl == null) {
      throw new UnsupportedOperationException("Invalid ejb ref");
    }

    Container container = localObjectImpl.getContainer();
    EjbDescriptor ejbDesc = container.getEjbDescriptor();
    boolean isStatefulBean = false;

    if (ejbDesc.getType().equals(EjbSessionDescriptor.TYPE)) {

      EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDesc;
      isStatefulBean = sessionDesc.isStateful();
    }

    if (!isStatefulBean) {

      // TODO 299 impl is incorrectly calling isRemoved for stateless/singleton
      // beans.  Until it's fixed just return false. Otherwise, any app acquiring
      // stateless/singleton references via 299 will fail until bug is fixed.
      return false;

      // TODO reenable this per SessionObjectReference.isRemoved SPI
      // throw new UnsupportedOperationException("ejbRef for ejb " +
      //   ejbDesc.getName() + " is not a stateful bean ");
    }

    boolean removed = false;

    try {
      ((BaseContainer) container).checkExists(localObjectImpl);
    } catch (Exception e) {
      removed = true;
    }

    return removed;
  }
Example #5
0
  public void requestDelete(BaseContainer view) {
    try {
      // For list items, getParent twice will get its BaseContainer.
      if (view.getParent().getParent() instanceof BaseContainer) {
        BaseContainer container = (BaseContainer) view.getParent().getParent();
        int index = this.indexOfChild(container);
        //                if (index < 1){
        //                    return;
        //                }
        //                final BaseContainer toDel = (BaseContainer) this.getChildAt(index - 1);
        //                if (container.getType() == Constants.TYPE_TODO && toDel.getType() ==
        // Constants.TYPE_TODO){
        //                    this.removeView(toDel);
        //                } else {
        this.removeView((View) view.getParent().getParent());
        this.addView(new Text(getContext()), index);
        //                }
        return;
      }
    } catch (NullPointerException e) {
      // Eat it.
    }

    int index = this.indexOfChild(view);
    if (index < 1) {
      return;
    }
    final BaseContainer toDel = (BaseContainer) this.getChildAt(index - 1);
    if (toDel.getType() == Constants.TYPE_TEXT && toDel.isEmpty()) {
      removeView(toDel);
      return;
    }
    if (view.getType() == Constants.TYPE_TEXT && view.isEmpty() && index != getChildCount() - 1) {
      removeView(view);
      return;
    }
    if (toDel.getType() == Constants.TYPE_TODO) {
      removeView(toDel);
      return;
    }
    String which = null;
    switch (toDel.getType()) {
      case Constants.TYPE_IMAGE:
        which = "Image";
        break;
      case Constants.TYPE_ATT:
        which = "File";
        break;
      case Constants.TYPE_REC:
        which = "Voice";
        break;
    }
    if (which == null) {
      return;
    }

    new AlertDialog.Builder(getContext())
        .setTitle("Confirm")
        .setMessage("Delete " + which + " ?")
        .setPositiveButton(
            "Sure",
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                EditView.this.removeView(toDel);
                dialog.dismiss();
              }
            })
        .setNegativeButton(
            "No",
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
              }
            })
        .create()
        .show();
  }
Example #6
0
  public String exportJSON(String where) {
    File file = new File(where);
    if (!file.exists()) {
      file.mkdirs();
    }
    file = new File(where + "content.json");
    try {
      file.createNewFile();
    } catch (IOException e) {
      e.printStackTrace();
    }
    ArrayList<Object> content = new ArrayList<>();
    Gson gson = new Gson();
    BaseContainer e;
    int empty = 0;
    for (int i = 0; i < getChildCount(); i++) {
      e = (BaseContainer) getChildAt(i);
      switch (e.getType()) {
        case Constants.TYPE_TEXT:
          if (!e.isEmpty()) {
            content.add(((ElementBean) e.getJsonBean()).setIndex(i - empty));
          } else {
            empty++;
          }
          break;
        case Constants.TYPE_IMAGE:
          if (!e.isEmpty()) {
            content.add(((ElementBean) e.getJsonBean()).setIndex(i - empty));
          } else {
            empty++;
          }
          break;
        case Constants.TYPE_TODO:
          if (!e.isEmpty()) {
            content.add(((ElementBean) e.getJsonBean()).setIndex(i - empty));
          } else {
            empty++;
          }
          break;
        case Constants.TYPE_ATT:
          if (!e.isEmpty()) {
            content.add(((ElementBean) e.getJsonBean()).setIndex(i - empty));
          } else {
            empty++;
          }
          break;
        case Constants.TYPE_ITEM:
          if (!e.isEmpty()) {
            content.add(((ElementBean) e.getJsonBean()).setIndex(i - empty));
          } else {
            empty++;
          }
          break;
        default:
          break;
      }
    }
    FileWriter dos = null;
    try {
      dos = new FileWriter(file);
      dos.write(gson.toJson(content));
    } catch (FileNotFoundException e1) {
      e1.printStackTrace();
    } catch (IOException e1) {
      e1.printStackTrace();
    } finally {
      if (dos != null)
        try {
          dos.close();
        } catch (IOException e1) {
          e1.printStackTrace();
        }
    }

    return file.getName();
  }