Package net.sf.mvc.mobile.command

Examples of net.sf.mvc.mobile.command.ActionCommand


  // setView is called before load
  public void setView(Displayable v) {
    this.view = (EnterNameView) v;
   
    
    view.addCommand(new ActionCommand("Say hello",Command.SCREEN, 1){
      public Navigation execute(Displayable d) throws Exception {
        return new Navigation("say-hello",view.getName());
      }     
    });
    /* Please note that the command above can't be writter as
     *     view.addCommand(new NavigationCommand(
     *       new Navigation("say-hello",  view.getName()), "Say hello", Command.SCREEN, 1));
     * because view.getName() has to be evaluated each time the command is executed
     */
   
    view.addCommand(new ActionCommand("Quit",Command.SCREEN, 9){
      public Navigation execute(Displayable d) throws Exception {
        controler.getMidlet().notifyDestroyed();
        return null;
      }     
    });
    view.addCommand(new NavigationCommand(new Navigation("say-hello", null),
        "Slow load", Command.SCREEN, 2));
    view.addCommand(new ActionCommand("Slow action", Command.SCREEN, 3){
      public Navigation execute(Displayable d) throws Exception {
        String name = view.getName();
        controler.progressListner.setMaxValue(name.length());
        for(int i=0;i<name.length();++i) {
          //slow operation:
View Full Code Here


 

  public void setView(Displayable v) {
    this.view = (SayHelloView) v;
   
    view.addCommand(new ActionCommand("Edit", Command.ITEM, 1) {
      public Navigation execute(Displayable d) throws Exception {
        System.out.println(".execute(), name="+name);
        return new Navigation("enter-name", "Edit your name", name);
      }     
    });
View Full Code Here

      gauge = new Gauge(labelPrefix, false, 100, 50);
    else
      gauge = new Gauge(labelPrefix, false, -1 /*Gauge.INDEFINITE*/,
          0 /*Gauge.CONTINUOUS_RUNNING*/);
    append(gauge);
    addCommand(new ActionCommand("${abort}",Command.BACK, 1){
      public Navigation execute(Displayable d) throws Exception {
        throw new InterruptedException();
      }     
    });
  }
View Full Code Here

      public void run() {
        Displayable progressView = progressListner.getDisplay();
        try {
          //TODO: start after .5 sec
          setView(progressView);
          ActionCommand command = (ActionCommand) c;
          Navigation navigation = command.execute(d);
          if (navigation != null)
            show(navigation.getName(), navigation.getParameter());
          else
            back();
        } catch (InterruptedException ex) {
View Full Code Here

      setView(previousView);
  }

  protected void quit() {
    Alert alert = new Alert("${quit}?","${quit.or.restart}?",null, AlertType.CONFIRMATION);
    alert.addCommand(new ActionCommand("${quit}", Command.BACK, 1){
      public Navigation execute(Displayable d) throws Exception {
        midlet.notifyDestroyed();
        return null;
      }           
    });
    alert.addCommand(new ActionCommand("${restart}", Command.OK, 2){
      public Navigation execute(Displayable d) throws Exception {
        start();
        return null;
      }     
    });
View Full Code Here

    ex.printStackTrace();
    Alert alert = new Alert("${error}");
    alert.setString(ex+(ex.getMessage() == null ? "" : ":"+ex.getMessage()));
    alert.setType(AlertType.ERROR);
    alert.setTimeout(Alert.FOREVER);
    alert.addCommand(new ActionCommand("${OK}", Command.OK, 1){
      public Navigation execute(Displayable d) throws Exception {
        back();
        return null;
      }     
    });
    alert.addCommand(new ActionCommand("${quit}", Command.BACK, 1){
      public Navigation execute(Displayable d) throws Exception {
        midlet.notifyDestroyed();
        return null;
      }           
    });
View Full Code Here

    view.setMucus((Mucus)parameter);
  }

  public void setView(Displayable v) {
    this.view = (MucusEditorView) v;
    view.addCommand(new ActionCommand("${ok}", Command.SCREEN, 1) {
      public Navigation execute(Displayable d) throws Exception {
        return new Navigation("mucus-editor", view.getMucus());
      }     
    });
    view.addCommand(new NavigationCommand("mucus-editor","${back}",Command.BACK,2));
View Full Code Here

    }
  }

  public void setView(Displayable v) {
    this.list = (List) v;
    list.addCommand(new ActionCommand("${edit}", Command.ITEM, 1) {
      public Navigation execute(Displayable d) throws Exception {
        Mucus mucus = (Mucus) registry.elementAt(list
            .getSelectedIndex());
        return new Navigation("edit-mucus", mucus);
      }
    });
    list.addCommand(new ActionCommand("${add}", Command.SCREEN, 2) {
      public Navigation execute(Displayable d) throws Exception {
        return new Navigation("edit-mucus", new Mucus());
      }
    });
    list.addCommand(new ActionCommand("${remove}", Command.ITEM, 3) {
      public Navigation execute(Displayable d) throws Exception {
        Mucus mucus = (Mucus) registry.elementAt(list
            .getSelectedIndex());
        rms.deleteRecord(mucus.getId());
        refresh();
        return null;
      }
    });
    list.addCommand(new ActionCommand("${default}", Command.ITEM, 3) {
      public Navigation execute(Displayable d) throws Exception {
        rms.closeRecordStore();
        MucusRegistry.close();
        RecordStore.deleteRecordStore(MucusRegistry.MUCUS_REGISTRY);
        rms = RecordStore.openRecordStore(MucusRegistry.MUCUS_REGISTRY,
            true);
        saveDefaults();
        refresh();
        return null;
      }
    });
    list.addCommand(new ActionCommand("${back}", Command.BACK, 10) {
      public Navigation execute(Displayable d) throws Exception {
        MucusRegistry.close();
        return new Navigation("input", null);
      }
    });
View Full Code Here

  }

  public void setView(Displayable view) {
    view.addCommand(new NavigationCommand("quit", "${quit}", Command.SCREEN, 9));
    //#ifdef FILE_API
    view.addCommand(new ActionCommand("${export}", Command.SCREEN, 8) {
      public Navigation execute(Displayable d) throws Exception {
        Exporter exporter = new Exporter();
       
        javax.microedition.io.file.FileConnection fc =
          (javax.microedition.io.file.FileConnection) Connector.open(CSV_PATH, Connector.READ_WRITE);
        try {
          if (fc.exists())
            fc.delete();
          fc.create();
          exporter.exportToCSV(fc.openOutputStream(), controler);
        } finally {
          fc.close();
        }
        return null;
      }
    });
    view.addCommand(new ActionCommand("${import}", Command.SCREEN, 8) {
      public Navigation execute(Displayable d) throws Exception {
        Exporter exporter = new Exporter();
       
        javax.microedition.io.file.FileConnection fc =
          (javax.microedition.io.file.FileConnection) Connector.open(CSV_PATH,
            Connector.READ);
        try {
          exporter.importFromCSV(fc.openDataInputStream(), fc.fileSize(), controler);
        } finally {
          fc.close();
        }
        return null;
      }
    });
    //#endif

    //#ifdef DEBUG
    view.addCommand(new ActionCommand("D:sample data", Command.SCREEN, 101) {
      public Navigation execute(Displayable d) throws Exception {
        Calendar date = Calendar.getInstance();
        Random random = new Random();
        controler.progressListner.setMaxValue(30);
        Observation o = null;
        Period period = new Period(new Date());
        controler.getPeriodDAO().setObservationIds(period, new Vector());
        for(int i=1; i < 5; ++i) {
          date.set(Calendar.DAY_OF_MONTH, i);
          o = new Observation(date.getTime(),
              Observation.NO_TEMPERATURE,
              MucusRegistry.instance().find(1),
              true, random.nextInt() % 5 == 0, "");
          LogicDAO.addObservationToPeriod(o, new Period[]{period}, controler);
          controler.progressListner.setValue(i);
        }
        for (int i = 5; i < 30; ++i) {
          date.set(Calendar.DAY_OF_MONTH, i);
          o = new Observation(date.getTime(),
              3620 + random.nextInt() % 60,
              MucusRegistry.instance().find(i % 3 + 1),
              false, random.nextInt() % 10 == 0, "");
          LogicDAO.addObservationToPeriod(o, new Period[]{period}, controler);
          controler.progressListner.setValue(i);
        }
        return new Navigation("graph", period, o);
      }
    });   
    view.addCommand(new ActionCommand("D:reset rms", Command.SCREEN, 102){
      public Navigation execute(Displayable d) throws Exception {
        controler.getPeriodDAO().deleteAll();
        controler.getObservationDAO().deleteAll();
        return new Navigation("quit",null);
      }     
View Full Code Here

  public void setView(Displayable v) {
    super.setView(v);
    this.view = (GraphView) v;

    selectCommand = new ActionCommand("${select}", Command.SCREEN, 1) {
      public Navigation execute(Displayable d) throws Exception {
        GraphView view = (GraphView) d;
        Observation observation = view.getSelectedObservation();
        return new Navigation("input", period, observation);
      }
    };
    view.addCommand(selectCommand);
    view.addCommand(new ActionCommand("${enter.new}", Command.SCREEN, 2) {
      public Navigation execute(Displayable d) throws Exception {
        return new Navigation("input", period, new Observation());
      }
    });
    view.addCommand(new ActionCommand("${history}", Command.SCREEN, 5) {
      public Navigation execute(Displayable d) throws Exception {
        return new Navigation("history", period);
      }
    });
    view.addCommand(new ActionCommand("${delete}", Command.SCREEN, 3){
      public Navigation execute(Displayable d) throws Exception {
        Observation observation = view.getSelectedObservation();
        if(observation != null) {
          LogicDAO.removeObservation(controler, observation, period);
          return new Navigation("graph", period, observation);
View Full Code Here

TOP

Related Classes of net.sf.mvc.mobile.command.ActionCommand

Copyright © 2018 www.massapicom. 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.